Author: vyemialyanchyk
Date: 2010-12-06 11:00:50 -0500 (Mon, 06 Dec 2010)
New Revision: 27192
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
Log:
https://jira.jboss.org/browse/JBIDE-7804 - fixed
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2010-12-06
15:18:53 UTC (rev 27191)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2010-12-06
16:00:50 UTC (rev 27192)
@@ -142,7 +142,7 @@
SchemaExportAction_error_while_performing_schemaexport={0} error(s) while performing
SchemaExport, see Error Log for details
SchemaExportAction_exception_running_schemaexport=Exception while running SchemaExport
SchemaExportAction_run_schemaexport=Run SchemaExport
-SchemaExportAction_sure_run_schemaexport=Are you sure you want to run SchemaExport on
''{0}''?
+SchemaExportAction_sure_run_schemaexport=Run SchemaExport will create/recreate all tables
in DB.\nAll data in existing tables will be lost.\nAre you sure you want to run
SchemaExport on ''{0}''?
ClearPlaceHolderJob_removing_place_holder=Removing place holder for pending node
PendingNode_error_getting_images=Error while getting images
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-12-06
15:18:53 UTC (rev 27191)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/views/SchemaExportAction.java 2010-12-06
16:00:50 UTC (rev 27192)
@@ -23,10 +23,13 @@
import java.util.Iterator;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Shell;
import org.hibernate.HibernateException;
+import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
@@ -61,35 +64,57 @@
setId(SCHEMAEXPORT_ACTIONID);
}
+ /**
+ * Convenience method to open a standard warning Yes/No dialog.
+ *
+ * @param parent the parent shell of the dialog, or <code>null</code> if
none
+ * @param title the dialog's title, or <code>null</code> if none
+ * @param msg the message
+ * @return <code>true</code> if the user presses the Yes button,
+ * <code>false</code> otherwise
+ */
+ public static boolean openWarningYesNoDlg(Shell parent, String title, String msg) {
+ String[] dialogButtonLabels = new String[] { IDialogConstants.YES_LABEL,
+ IDialogConstants.NO_LABEL };
+ MessageDialog dialog = new MessageDialog(parent, title, null, msg,
+ MessageDialog.WARNING, dialogButtonLabels, 0);
+ return dialog.open() == 0;
+ }
+
public void doRun() {
for (Iterator<?> i = getSelectedNonResources().iterator(); i.hasNext();) {
+ Object node = i.next();
+ if (!(node instanceof ConsoleConfiguration)) {
+ continue;
+ }
+ final ConsoleConfiguration config = (ConsoleConfiguration) node;
try {
- Object node = i.next();
- if ( node instanceof ConsoleConfiguration ) {
- final ConsoleConfiguration config = (ConsoleConfiguration) node;
config.execute( new Command() {
@SuppressWarnings("unchecked")
public Object execute() {
+ final Configuration cfg = config.getConfiguration();
+ if (cfg == null) {
+ return null;
+ }
String out =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_sure_run_schemaexport,
config.getName());
- if ( config.getConfiguration() != null
- && MessageDialog.openConfirm( viewer.getControl().getShell(),
- HibernateConsoleMessages.SchemaExportAction_run_schemaexport,
- out ) ) {
- SchemaExport export = new SchemaExport( config
- .getConfiguration() );
- export.create( false, true );
- if ( !export.getExceptions().isEmpty() ) {
- Iterator<Throwable> iterator = export.getExceptions().iterator();
- int cnt = 1;
- while ( iterator.hasNext() ) {
- Throwable element = iterator.next();
- String outStr =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport,
cnt++);
- HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element );
- }
- HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(),
- NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport,
cnt - 1),
- (Throwable)null );
+ boolean res = openWarningYesNoDlg(viewer.getControl().getShell(),
+ HibernateConsoleMessages.SchemaExportAction_run_schemaexport, out);
+ if (!res) {
+ return null;
+ }
+ SchemaExport export = new SchemaExport(cfg);
+ export.create(false, true);
+ if (!export.getExceptions().isEmpty()) {
+ Iterator<Throwable> iterator = export.getExceptions().iterator();
+ int cnt = 1;
+ while (iterator.hasNext()) {
+ Throwable element = iterator.next();
+ String outStr =
NLS.bind(HibernateConsoleMessages.SchemaExportAction_errornum_while_performing_schemaexport,
cnt++);
+ HibernateConsolePlugin.getDefault().logErrorMessage(outStr, element);
}
+ HibernateConsolePlugin.getDefault().showError(viewer.getControl().getShell(),
+ NLS.bind(HibernateConsoleMessages.SchemaExportAction_error_while_performing_schemaexport,
cnt - 1),
+ (Throwable)null );
}
return null;
}
@@ -97,7 +122,6 @@
viewer.refresh( node ); // todo: should we do it here or should
// the view just react to config being
// build ?
- }
}
catch (HibernateException he) {
HibernateConsolePlugin.getDefault().showError(