Author: dgeraskov
Date: 2010-01-13 03:57:24 -0500 (Wed, 13 Jan 2010)
New Revision: 19727
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePropertiesComposite.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5643
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2010-01-13
08:32:14 UTC (rev 19726)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java 2010-01-13
08:57:24 UTC (rev 19727)
@@ -320,9 +320,7 @@
private void handleConfigurationFileSetup() {
int defaultChoice = 0;
- IPath initialPath = getConfigurationFilePath() != null ? getConfigurationFilePath() :
null;
-
- if(initialPath!=null) {
+ if(getConfigurationFilePath()!=null) {
defaultChoice = 1;
}
MessageDialog dialog =
createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file,
HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml,
defaultChoice);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePropertiesComposite.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePropertiesComposite.java 2010-01-13
08:32:14 UTC (rev 19726)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/internal/persistence/details/HibernatePropertiesComposite.java 2010-01-13
08:57:24 UTC (rev 19727)
@@ -15,6 +15,12 @@
import java.util.List;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jpt.ui.WidgetFactory;
import org.eclipse.jpt.ui.details.JpaPageComposite;
import org.eclipse.jpt.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
@@ -30,9 +36,14 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.hibernate.eclipse.console.utils.DriverClassHelpers;
+import org.hibernate.eclipse.console.wizards.NewConfigurationWizard;
+import org.hibernate.eclipse.console.wizards.NewConfigurationWizardPage;
import org.hibernate.eclipse.launch.PathHelper;
import
org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties;
import org.jboss.tools.hibernate.jpt.ui.wizard.Messages;
@@ -89,7 +100,7 @@
final WritablePropertyValueModel<String> driverHolder = buildDriverHolder();
final WritablePropertyValueModel<String> urlHolder = buildUrlHolder();
- Button b = addButton(section,
HibernateConsoleMessages.CodeGenerationSettingsTab_browse, createSetupAction());
+ Button b = addButton(section, HibernateConsoleMessages.CodeGenerationSettingsTab_setup,
createSetupAction());
cfgFile = addLabeledText(section,
HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file +
':', buildConfigFileHolder(),
b, null);
@@ -174,17 +185,58 @@
return new Runnable() {
public void run() {
IPath initialPath = getConfigurationFilePath();
- IPath[] paths = DialogSelectionHelper.chooseFileEntries(getControl().getShell(),
initialPath,
- new IPath[0],
- HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file,
- HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml,
- new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml },
false, false,
- true);
- if (paths != null && paths.length == 1) {
- // TODO update to subpath
- cfgFile.setText((paths[0]).toOSString());
+ int defaultChoice = 0;
+ if(initialPath!=null) {
+ defaultChoice = 1;
+ }
+ MessageDialog dialog =
createSetupDialog(HibernateConsoleMessages.ConsoleConfigurationMainTab_setup_configuration_file,
HibernateConsoleMessages.ConsoleConfigurationMainTab_do_you_want_to_create_new_cfgxml,
defaultChoice);
+ int answer = dialog.open();
+ if(answer==0) { // create new
+ handleConfigurationFileCreate();
+ } else if (answer==1) { // use existing
+ handleConfigurationFileBrowse();
}
}
+
+ private MessageDialog createSetupDialog(String title, String question, int
defaultChoice){
+ return new MessageDialog(getShell(),
+ title,
+ null,
+ question,
+ MessageDialog.QUESTION,
+ new String[] { HibernateConsoleMessages.ConsoleConfigurationMainTab_create_new,
HibernateConsoleMessages.ConsoleConfigurationMainTab_use_existing,
IDialogConstants.CANCEL_LABEL},
+ defaultChoice);
+ }
+
+ private void handleConfigurationFileBrowse() {
+ IPath initialPath = getConfigurationFilePath();
+ IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(), initialPath, new
IPath[0],
HibernateConsoleMessages.ConsoleConfigurationMainTab_select_hibernate_cfg_xml_file,
HibernateConsoleMessages.ConsoleConfigurationMainTab_choose_file_to_use_as_hibernate_cfg_xml,
new String[] {HibernateConsoleMessages.ConsoleConfigurationMainTab_cfg_xml}, false, false,
true);
+ if(paths!=null && paths.length==1) {
+ cfgFile.setText( (paths[0]).toOSString() );
+ }
+ }
+
+ private void handleConfigurationFileCreate() {
+ StructuredSelection selection = null;
+ NewConfigurationWizard wizard = new NewConfigurationWizard();
+ wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY );
+ IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
+ wdialog.create();
+ IWizardPage configPage =
wizard.getPage(HibernateConsoleMessages.ConsoleConfigurationMainTab_wizard_page);
+ if (configPage != null && configPage instanceof NewConfigurationWizardPage){
+ ((NewConfigurationWizardPage)configPage).setCreateConsoleConfigurationVisible(false);
+ }
+ // This opens a dialog
+ if (wdialog.open() == Window.OK){
+ WizardNewFileCreationPage createdFilePath =
((WizardNewFileCreationPage)wizard.getStartingPage());
+ if(createdFilePath!=null) {
+ // createNewFile() does not creates new file if it was created by wizard (OK was
pressed)
+ cfgFile.setText(createdFilePath.createNewFile().getFullPath().toOSString());
+ }
+ }
+ }
};
}
@@ -297,6 +349,12 @@
if ("".equals(value))value = null;//$NON-NLS-1$
subject.setUsername(value);
}
+
+ @Override
+ protected void propertyChanged() {
+ // TODO Auto-generated method stub
+ super.propertyChanged();
+ }
};
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2010-01-13
08:32:14 UTC (rev 19726)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.ui/src/org/jboss/tools/hibernate/jpt/ui/wizard/GenerateInitWizardPage.java 2010-01-13
08:57:24 UTC (rev 19727)
@@ -47,6 +47,7 @@
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.hibernate.eclipse.console.utils.DriverClassHelpers;
+import org.hibernate.eclipse.console.utils.LaunchHelper;
import org.hibernate.eclipse.launch.PathHelper;
import org.hibernate.tool.hbm2x.StringUtils;
import org.hibernate.util.StringHelper;
@@ -146,7 +147,7 @@
consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
- ConsoleConfiguration[] cfg =
KnownConfigurations.getInstance().getConfigurationsSortedByName();
+ ConsoleConfiguration[] cfg = LaunchHelper.findFilteredSortedConsoleConfigs();
String[] names = new String[cfg.length];
for (int i = 0; i < cfg.length; i++) {
ConsoleConfiguration configuration = cfg[i];