[jbosstools-commits] JBoss Tools SVN: r6966 - in trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse: launch and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Mar 17 11:06:59 EDT 2008


Author: dgeraskov
Date: 2008-03-17 11:06:58 -0400 (Mon, 17 Mar 2008)
New Revision: 6966

Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/xpl/DialogSelectionHelper.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
   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/ConsoleConfigurationTab.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/DirectoryBrowseField.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1609

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/xpl/DialogSelectionHelper.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/xpl/DialogSelectionHelper.java	2008-03-17 15:01:26 UTC (rev 6965)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/xpl/DialogSelectionHelper.java	2008-03-17 15:06:58 UTC (rev 6966)
@@ -22,6 +22,7 @@
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jdt.internal.ui.wizards.TypedElementSelectionValidator;
+import org.eclipse.jdt.internal.ui.wizards.buildpaths.FolderSelectionDialog;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
@@ -77,7 +78,7 @@
 		}
 		IResource focus= initialSelection != null ? root.findMember(initialSelection) : null;
 		
-		ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider() );
+		ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider() );
 		dialog.setValidator(validator);
 		dialog.setAllowMultiple(allowMultiple);
 		dialog.setTitle(title);
@@ -98,5 +99,40 @@
 		}
 		return null;
 	}
+	
+	public static IPath[] chooseFolderEntries(Shell shell, IPath initialSelection, String title, String description, boolean allowMultiple) {
+		List clazzes = new ArrayList();
+		clazzes.add(IFolder.class);
+		clazzes.add(IProject.class);
 
+		Class[] acceptedClasses = (Class[]) clazzes.toArray(new Class[clazzes.size()]);
+				
+		TypedElementSelectionValidator validator= new TypedElementSelectionValidator(acceptedClasses, true);
+		IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
+		IResource focus= initialSelection != null ? root.findMember(initialSelection) : null;
+		
+		ElementTreeSelectionDialog dialog= null;
+		dialog = new FolderSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider() );
+		//	dialog = new FileFolderSelectionDialog(shell, allowMultiple, allowDirectories ? IResource.FOLDER : IResource.FILE );
+		
+		dialog.setValidator(validator);
+		dialog.setAllowMultiple(allowMultiple);
+		dialog.setTitle(title);
+		dialog.setMessage(description);
+		dialog.setInput(root);
+		dialog.setSorter(new ResourceSorter(ResourceSorter.NAME) );
+		dialog.setInitialSelection(focus);
+
+		if (dialog.open() == Window.OK) {
+			Object[] elements= dialog.getResult();
+			IPath[] res= new IPath[elements.length];
+			for (int i= 0; i < res.length; i++) {
+				IResource elem= (IResource)elements[i];
+				res[i]= elem.getFullPath();
+			}
+			return res;
+		}
+		return null;
+	}
+
 }

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java	2008-03-17 15:01:26 UTC (rev 6965)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java	2008-03-17 15:06:58 UTC (rev 6966)
@@ -123,7 +123,8 @@
 		
 		outputdir = new StringButtonDialogField(new IStringButtonAdapter() {
 			public void changeControlPressed(DialogField field) {
-				IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),  PathHelper.pathOrNull(outputdir.getText()), new IPath[0], "Select output directory", "Choose directory in which the generated files will be stored", new String[] {"cfg.xml"}, false, true, false);
+				//IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),  PathHelper.pathOrNull(outputdir.getText()), new IPath[0], "Select output directory", "Choose directory in which the generated files will be stored", new String[] {"cfg.xml"}, false, true, false);
+				IPath[] paths = DialogSelectionHelper.chooseFolderEntries(getShell(),  PathHelper.pathOrNull(outputdir.getText()), "Select output directory", "Choose directory in which the generated files will be stored", false);
 				if(paths!=null && paths.length==1) {
 					outputdir.setText( ( (paths[0]).toOSString() ) );
 				}					

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	2008-03-17 15:01:26 UTC (rev 6965)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationMainTab.java	2008-03-17 15:06:58 UTC (rev 6966)
@@ -13,6 +13,8 @@
 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+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;
@@ -51,7 +53,6 @@
 	private Button jpaMode;
 	private Button annotationsMode;
 	private Button confbutton;
-	private Button createconfbutton;
 	
 	private Text propertyFileText;
 	private Text configurationFileText;
@@ -112,33 +113,23 @@
 	}
 	
 	private void createPropertyFileEditor(Composite parent) {
-		Group group = createGroup( parent, "Property file:", 3 );
+		Group group = createGroup( parent, "Property file:" );
 		propertyFileText = createBrowseEditor( parent, group);
-		createNewFileButton( group, new SelectionAdapter() {
+		createSetupButton( group, new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
-				handlePropertyFileCreate();
+				handlePropertyFileSetup();
 			}
-		} );
-		createBrowseButton( group, new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				handlePropertyFileBrowse();
-			}
 		} );		
 	}
 	
 
 	private void createConfigurationFileEditor(Composite parent) {
-		Group group = createGroup( parent, "Configuration file:", 3 );
+		Group group = createGroup( parent, "Configuration file:" );
 		configurationFileText = createBrowseEditor( parent, group);
-		createconfbutton = createNewFileButton( group, new SelectionAdapter() {
+		confbutton = createSetupButton( group, new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
-				handleConfigurationFileCreate();
+				handleConfigurationFileSetup();
 			}
-		} );
-		confbutton = createBrowseButton( group, new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				handleConfigurationFileBrowse();
-			}
 		});
 	}
 	
@@ -183,6 +174,24 @@
 	
 	public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {}
 	
+	private void handlePropertyFileSetup() {
+		int defaultChoice = 0;
+		IPath initialPath = getPropertyFilePath() != null ? getPropertyFilePath() : null;
+    	
+		if(initialPath!=null) {
+    		defaultChoice = 1;
+    	}
+		MessageDialog dialog = createSetupDialog("Setup property file", "Do you want to create a new property file or use an existing one ?", defaultChoice);
+
+		int answer = dialog.open();
+		if(answer==0) { // create new
+			handlePropertyFileCreate();	
+		} else if (answer==1) { // use existing
+			handlePropertyFileBrowse();		
+		} 
+	}
+	
+	
 	private void handlePropertyFileBrowse() {
 		IPath initialPath = getPropertyFilePath() != null ? getPropertyFilePath() : new Path(getProjectName());
 		IPath[] paths = org.hibernate.eclipse.console.utils.xpl.DialogSelectionHelper.chooseFileEntries(getShell(),  initialPath, new IPath[0], "Select property file", "Choose file to use as hibernate.properties", new String[] {"properties"}, false, false, true);
@@ -244,7 +253,32 @@
 			wdialog.open();
 	}
 	
+	private MessageDialog createSetupDialog(String title, String question, int defaultChoice){
+		return new MessageDialog(getShell(), 
+				title, 
+				null, 
+				question, 
+				MessageDialog.QUESTION, 
+				new String[] { "Create &new...", "Use &existing...", IDialogConstants.CANCEL_LABEL}, 
+				defaultChoice);
+	}
 	
+	private void handleConfigurationFileSetup() {
+		int defaultChoice = 0;
+		IPath initialPath = getConfigurationFilePath() != null ? getConfigurationFilePath() : null;
+		
+		if(initialPath!=null) {
+    		defaultChoice = 1;
+    	}
+		MessageDialog dialog = createSetupDialog("Setup configuration file", "Do you want to create a new *.cfg.xml or use an existing one ?", defaultChoice);
+		int answer = dialog.open();
+		if(answer==0) { // create new
+			handleConfigurationFileCreate();	
+		} else if (answer==1) { // use existing
+			handleConfigurationFileBrowse();		
+		}  
+	}
+	
 	private void handleConfigurationFileBrowse() {
 		IPath initialPath = getConfigurationFilePath() != null ? getConfigurationFilePath() : new Path(getProjectName());
 		IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),  initialPath, new IPath[0], "Select hibernate.cfg.xml file", "Choose file to use as hibernate.cfg.xml", new String[] {"cfg.xml"}, false, false, true);
@@ -307,7 +341,6 @@
 		
 		configurationFileText.setEnabled( /* TODO !configurationFileWillBeCreated && */ !getConfigurationMode().equals( ConfigurationMode.JPA ) );
 		confbutton.setEnabled( !getConfigurationMode().equals( ConfigurationMode.JPA ) );
-		createconfbutton.setEnabled(confbutton.isEnabled());
 		
 		persistenceUnitNameText.setEnabled( getConfigurationMode().equals( ConfigurationMode.JPA) );
 		

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java	2008-03-17 15:01:26 UTC (rev 6965)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ConsoleConfigurationTab.java	2008-03-17 15:06:58 UTC (rev 6966)
@@ -41,6 +41,12 @@
 		return button;
 	}
 	
+	protected Button createSetupButton(Group group, SelectionListener selectionListener) {
+		Button button = createPushButton(group, "Setup...", null); 
+		button.addSelectionListener(selectionListener);
+		return button;
+	}
+	
 	protected Button createNewFileButton(Group group, SelectionListener selectionListener) {
 		Button button = createPushButton(group, "Create New", null); 
 		button.addSelectionListener(selectionListener);

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/DirectoryBrowseField.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/DirectoryBrowseField.java	2008-03-17 15:01:26 UTC (rev 6965)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/DirectoryBrowseField.java	2008-03-17 15:06:58 UTC (rev 6966)
@@ -94,7 +94,7 @@
 	
 	protected void browseWorkspace ()
 	{
-		IPath[] paths = DialogSelectionHelper.chooseFileEntries(filesystemBrowse.getShell(),  initialWorkspacePath, new IPath[0], dialogTitle, dialogDescription, new String[0], false, true, false);
+		IPath[] paths = DialogSelectionHelper.chooseFolderEntries(filesystemBrowse.getShell(),  initialWorkspacePath, dialogTitle, dialogDescription, false);
         if(paths!=null && paths.length==1) {
         	setText(paths[0].toOSString());
         }




More information about the jbosstools-commits mailing list