Author: dgeraskov
Date: 2008-08-26 09:11:58 -0400 (Tue, 26 Aug 2008)
New Revision: 9898
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
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/model/impl/ExporterDefinition.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/AddPropertyDialog.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-1913
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2008-08-26
11:18:46 UTC (rev 9897)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.java 2008-08-26
13:11:58 UTC (rev 9898)
@@ -493,6 +493,8 @@
public static String ExporterSettingsTab_select_exporter_you_want_to_add;
public static String ExporterSettingsTab_template_directory_for;
public static String ExporterSettingsTab_use_java5_syntax;
+ public static String ExporterSettingsTab_select_dir;
+ public static String ExporterSettingsTab_select_path;
public static String GeneralExceptionStatusHandler_exception_while_generating_code;
public static String GeneralExceptionStatusHandler_generating_code;
public static String PathHelper_does_not_exist;
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 2008-08-26
11:18:46 UTC (rev 9897)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2008-08-26
13:11:58 UTC (rev 9898)
@@ -484,6 +484,9 @@
ExporterSettingsTab_select_exporter_you_want_to_add=Select the exporter(s) you want to
add
ExporterSettingsTab_template_directory_for=Template directory for
ExporterSettingsTab_use_java5_syntax=Use Java 5 syntax
+ExporterSettingsTab_select_dir=Select directory
+ExporterSettingsTab_select_path=Select path
+ExporterSettingsTab_use_java5_syntax=Use Java 5 syntax
GeneralExceptionStatusHandler_exception_while_generating_code=Exception while generating
code
GeneralExceptionStatusHandler_generating_code=Generating code
PathHelper_does_not_exist={0} does not exist [{1}]
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java 2008-08-26
11:18:46 UTC (rev 9897)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java 2008-08-26
13:11:58 UTC (rev 9898)
@@ -111,9 +111,13 @@
propertyElements[i].getAttribute("description"), //$NON-NLS-1$
propertyElements[i].getAttribute("value"), //$NON-NLS-1$
Boolean.valueOf(propertyElements[i].getAttribute("required")).booleanValue());
//$NON-NLS-1$
- properties.put(property.getName(),property);
- }
- return properties;
+ String type = propertyElements[i].getAttribute("type");
+ if (type != null){
+ property.setType(type);
+ }
+ properties.put(property.getName(),property);
+ }
+ return properties;
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java 2008-08-26
11:18:46 UTC (rev 9897)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java 2008-08-26
13:11:58 UTC (rev 9898)
@@ -33,6 +33,7 @@
private String defaultValue;
private String description;
private String name;
+ private String type = "string"; //$NON-NLS-1$
private boolean required;
public ExporterProperty () { }
@@ -43,6 +44,12 @@
this.defaultValue = defaultValue;
this.required = required;
}
+
+ public ExporterProperty (String name, String description, String defaultValue, boolean
required, String type)
+ {
+ this(name, description, defaultValue, required);
+ setType( type );
+ }
public String getDefaultValue() {
return defaultValue;
@@ -96,4 +103,18 @@
return description + " [" + name + "]";
//$NON-NLS-1$//$NON-NLS-2$
}
}
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/AddPropertyDialog.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/AddPropertyDialog.java 2008-08-26
11:18:46 UTC (rev 9897)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/AddPropertyDialog.java 2008-08-26
13:11:58 UTC (rev 9898)
@@ -1,10 +1,13 @@
package org.hibernate.eclipse.launch;
+import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
@@ -19,8 +22,12 @@
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -34,15 +41,24 @@
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.model.impl.ExporterFactory;
import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.eclipse.console.utils.DialogSelectionHelper;
import org.hibernate.util.StringHelper;
public class AddPropertyDialog extends TitleAreaDialog {
private final ExporterFactory ef;
private ComboViewer propertyCombo;
- private Text value;
+ private Control value;
+ private Button browseButton;
private String propertyName;
private String propertyValue;
+ private ModifyListener modifyListener = new ModifyListener() {
+
+ public void modifyText(ModifyEvent e) {
+ updateStatus();
+ }
+
+ };
protected AddPropertyDialog(Shell parentShell, ExporterFactory ef) {
super( parentShell );
@@ -56,35 +72,41 @@
Composite composite = new Composite(control,SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
- GridLayout layout = new GridLayout(2,false);
+ GridLayout layout = new GridLayout(3,false);
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
layout.marginWidth =
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
layout.verticalSpacing =
convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
layout.horizontalSpacing =
convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
composite.setLayout(layout);
- ModifyListener modifyListener = new ModifyListener() {
-
- public void modifyText(ModifyEvent e) {
- updateStatus();
- }
-
- };
-
Label label = new Label(composite, SWT.NONE);
label.setText( HibernateConsoleMessages.AddPropertyDialog_name );
Combo combo = new Combo(composite, SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN);
- combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL |
GridData.FILL_HORIZONTAL));
+ GridData pgd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
+ pgd.horizontalSpan = 2;
+ combo.setLayoutData(pgd);
combo.setFocus();
combo.addModifyListener( modifyListener );
propertyCombo = new ComboViewer(combo);
+
+ combo.addKeyListener(new KeyListener(){
+
+ public void keyPressed(KeyEvent e) {
+ disposeBrowseButton();
+ createTextValueComposite(2);
+ }
+
+ public void keyReleased(KeyEvent e) {}
+
+ });
+
label = new Label(composite, SWT.NONE);
label.setText( HibernateConsoleMessages.AddPropertyDialog_value );
value = new Text(composite, SWT.BORDER | SWT.LEAD );
value.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL |
GridData.FILL_HORIZONTAL));
- value.addModifyListener( modifyListener );
+ ((Text)value).addModifyListener( modifyListener );
initDefaultNames(ef, propertyCombo);
@@ -151,14 +173,73 @@
viewer.addSelectionChangedListener( new ISelectionChangedListener() {
+ private SelectionListener getSelectionListener(ExporterProperty prop){
+ if ("directory".equals(prop.getType())){ //$NON-NLS-1$
+ return new SelectionListener(){
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
PathHelper.pathOrNull(((Text)value).getText()), new Path[0],
+ HibernateConsoleMessages.ExporterSettingsTab_select_dir,
HibernateConsoleMessages.ExporterSettingsTab_select_dir,
+ new String[0], true, true, false);//$NON-NLS-1$
+ if(paths!=null && paths.length==1) {
+ ((Text)value).setText( ( (paths[0]).toOSString() ) );
+ }
+ }
+ };
+ } else if ("path".equals(prop.getType())){ //$NON-NLS-1$
+ return new SelectionListener(){
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),
PathHelper.pathOrNull(((Text)value).getText()), new Path[0],
+ HibernateConsoleMessages.ExporterSettingsTab_select_path,
HibernateConsoleMessages.ExporterSettingsTab_select_path,
+ new String[]{new String()}/*allow all files*/, true, true,
true);//$NON-NLS-1$
+ //IPath[] paths = DialogSelectionHelper.chooseFolderEntries(getShell(),
PathHelper.pathOrNull(((Text)value).getText()), "Select directories",
//$NON-NLS-1$
+ // "Choose directories", true);//$NON-NLS-1$
+ if(paths!=null && paths.length > 0) {
+ String strPath = paths[0].toOSString();
+ for (int i = 1; i < paths.length; i++) {
+ strPath += File.pathSeparator + paths[i].toOSString();
+ }
+ ((Text)value).setText( strPath );
+ }
+ }
+ };
+ }
+ return null;
+ }
+
+
public void selectionChanged(SelectionChangedEvent event) {
if(value==null) return;
IStructuredSelection iss = (IStructuredSelection) event.getSelection();
if(!iss.isEmpty()) {
- value.setText( ((ExporterProperty)iss.getFirstElement()).getDefaultValue() );
+ ExporterProperty prop = (ExporterProperty)iss.getFirstElement();
+ if ("boolean".equalsIgnoreCase(prop.getType())) { //$NON-NLS-1$
+ disposeBrowseButton();
+ createComboValueComposite(new String[]{String.valueOf(true),
String.valueOf(false)});
+ ((Combo)value).select(Boolean.valueOf(prop.getDefaultValue()).booleanValue() ? 0 :
1);
+ } else if ("directory".equalsIgnoreCase(prop.getType())//$NON-NLS-1$
+ || "path".equalsIgnoreCase(prop.getType())) { //$NON-NLS-1$
+ disposeBrowseButton();
+ createTextValueComposite(1);
+ ((Text) value).setText(prop.getDefaultValue());
+ createBrowseButton(getSelectionListener(prop));
+ } else {
+ disposeBrowseButton();
+ createTextValueComposite(2);
+ ((Text) value).setText(prop.getDefaultValue());
+ }
+ } else {
+ createTextValueComposite(2);
}
}
-
} );
viewer.setInput( ef );
if(viewer.getCombo().getItemCount()>0) {
@@ -166,7 +247,62 @@
}
}
-
+ private void disposeBrowseButton(){
+ if (browseButton != null){
+ Composite parent = browseButton.getParent();
+ browseButton.dispose();
+ browseButton = null;
+ parent.layout();
+ }
+ }
+
+ private void createBrowseButton(SelectionListener listener){
+ disposeBrowseButton();
+ browseButton = new Button(value.getParent(), SWT.PUSH);
+ browseButton.setText(HibernateConsoleMessages.ConsoleConfigurationTab_browse);
+ browseButton.setLayoutData(new GridData(GridData.END));
+ browseButton.addSelectionListener(listener);
+ value.getParent().layout();
+ }
+
+ private void createTextValueComposite(int span){
+ if (! (value instanceof Text)) {
+ Composite parent = value.getParent();
+ if (value != null){
+ value.dispose();
+ }
+ value = new Text(parent, SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN);
+ ((Text)value).addModifyListener( modifyListener );
+ GridData vgd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
+ vgd.horizontalSpan = span;
+ value.setLayoutData(vgd);
+ } else {
+ ((GridData)value.getLayoutData()).horizontalSpan = span;
+ ((Text)value).setText(new String());
+ }
+ value.getParent().layout();
+ }
+
+ private void createComboValueComposite(String[] items){
+ if (!(value instanceof Combo)) {
+ Composite parent = value.getParent();
+ if (value != null){
+ value.dispose();
+ }
+ value = new Combo(parent, SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN | SWT.READ_ONLY);
+ GridData bgd = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
+ bgd.horizontalSpan = 2;
+ value.setLayoutData(bgd);
+ ((Combo)value).setItems(items);
+ ((Combo)value).addModifyListener( modifyListener );
+ if (items != null && items.length > 0){
+ ((Combo)value).select(0);
+ }
+ parent.layout();
+ }
+ }
+
+
void updateStatus() {
getEnteredValues();
@@ -215,7 +351,11 @@
}
if(value!=null) {
- propertyValue = value.getText();
+ if (value instanceof Text) {
+ propertyValue = ((Text) value).getText();
+ } else if (value instanceof Combo) {
+ propertyValue = ((Combo) value).getText();
+ }
} else {
propertyValue = null;
}