1 5 package org.hibernate.eclipse.console.views; 6 7 import java.util.Iterator ; 8 9 import org.eclipse.jface.dialogs.MessageDialog; 10 import org.eclipse.jface.viewers.StructuredViewer; 11 import org.hibernate.HibernateException; 12 import org.hibernate.console.ConsoleConfiguration; 13 import org.hibernate.console.node.BaseNode; 14 import org.hibernate.eclipse.console.HibernateConsolePlugin; 15 import org.hibernate.eclipse.console.actions.ConsoleConfigurationBasedAction; 16 import org.hibernate.tool.hbm2ddl.SchemaExport; 17 18 22 public class SchemaExportAction extends ConsoleConfigurationBasedAction { 23 24 private StructuredViewer viewer; 25 26 29 protected SchemaExportAction(String text) { 30 super(text); 31 } 32 33 36 public SchemaExportAction(StructuredViewer selectionProvider) { 37 super("Run SchemaExport"); 38 this.viewer = selectionProvider; 39 } 40 41 public void doRun() { 42 for (Iterator i = getSelectedNonResources().iterator(); i.hasNext();) { 43 try { 44 BaseNode node = ((BaseNode) i.next()); 45 final ConsoleConfiguration config = node 46 .getConsoleConfiguration(); 47 config 48 .execute(new org.hibernate.console.ConsoleConfiguration.Command() { 49 public Object execute() { 50 if (config.getConfiguration() != null 51 && MessageDialog.openConfirm(viewer 52 .getControl().getShell(), 53 "Run SchemaExport", 54 "Are you sure you want to run SchemaExport on '" 55 + config.getName() 56 + "'?")) { 57 SchemaExport export = new SchemaExport( 58 config.getConfiguration()); 59 export.create(false, true); 60 if (!export.getExceptions().isEmpty()) { 61 Iterator iterator = export 62 .getExceptions().iterator(); 63 int cnt = 1; 64 while (iterator.hasNext()) { 65 Throwable element = (Throwable ) iterator 66 .next(); 67 HibernateConsolePlugin 68 .getDefault().logErrorMessage( 69 "Error " 70 + cnt++ 71 + " while performing SchemaExport", 72 element); 73 } 74 HibernateConsolePlugin 75 .getDefault().showError( 76 viewer.getControl() 77 .getShell(), 78 cnt 79 - 1 80 + " error(s) while performing SchemaExport, see Error Log for details", 81 null); 82 } 83 } 84 return null; 85 } 86 }); 87 viewer.refresh(node); } catch (HibernateException he) { 91 HibernateConsolePlugin.getDefault().showError( 92 viewer.getControl().getShell(), 93 "Exception while running SchemaExport", he); 94 } 95 } 96 } 97 98 103 protected boolean updateState(ConsoleConfiguration consoleConfiguration) { 104 return consoleConfiguration.hasConfiguration(); 105 } 106 } 107 | Popular Tags |