[jboss-cvs] jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen ...

Max Rydahl Andersen mandersen at jboss.com
Wed Mar 14 05:21:29 EDT 2007


  User: mandersen
  Date: 07/03/14 05:21:29

  Modified:    seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen  
                        QuestionDialog.java SeamGenProperty.java
  Log:
  final eclipsecon + minor improvements for seam presentation
  
  Revision  Changes    Path
  1.2       +217 -26   jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: QuestionDialog.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/QuestionDialog.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- QuestionDialog.java	15 Feb 2007 12:20:44 -0000	1.1
  +++ QuestionDialog.java	14 Mar 2007 09:21:29 -0000	1.2
  @@ -1,36 +1,59 @@
   package org.jboss.ide.seam.gen;
   
  +import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
  +import java.io.IOException;
   import java.util.Collections;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.Map;
   import java.util.Properties;
  +import java.util.Set;
   
  +import org.eclipse.core.runtime.CoreException;
  +import org.eclipse.core.runtime.Path;
  +import org.eclipse.debug.core.ILaunchConfiguration;
   import org.eclipse.jface.dialogs.IDialogConstants;
   import org.eclipse.jface.dialogs.IMessageProvider;
   import org.eclipse.jface.dialogs.TitleAreaDialog;
   import org.eclipse.swt.SWT;
   import org.eclipse.swt.events.ModifyEvent;
   import org.eclipse.swt.events.ModifyListener;
  +import org.eclipse.swt.events.SelectionAdapter;
  +import org.eclipse.swt.events.SelectionEvent;
  +import org.eclipse.swt.graphics.Point;
   import org.eclipse.swt.layout.GridData;
   import org.eclipse.swt.layout.GridLayout;
  +import org.eclipse.swt.widgets.Button;
   import org.eclipse.swt.widgets.Composite;
   import org.eclipse.swt.widgets.Control;
  +import org.eclipse.swt.widgets.DirectoryDialog;
  +import org.eclipse.swt.widgets.FileDialog;
   import org.eclipse.swt.widgets.Label;
   import org.eclipse.swt.widgets.Shell;
  +import org.eclipse.swt.widgets.TabFolder;
  +import org.eclipse.swt.widgets.TabItem;
   import org.eclipse.swt.widgets.Text;
  +import org.jboss.ide.seam.gen.actions.SeamGenAction;
   
   public class QuestionDialog extends TitleAreaDialog {
   
   	private final String title;
   	private final String description;
   	private final Map questions;
  +	private final Set groups;
   
  -	public QuestionDialog(Shell parentShell, String title, String description, Map questions) {
  +	protected Point getInitialSize() {
  +		return new Point(706,478);
  +	}
  +	
  +	public QuestionDialog(Shell parentShell, String title, String description, Map questions, Set groups) {
   		super( parentShell );
  +		setShellStyle(getShellStyle() | SWT.RESIZE  | SWT.MAX);
   		this.title = title;
   		this.description = description;
   		this.questions = questions;
  +		this.groups = groups;
   	}
   	
   	Map propertyToField = new HashMap();
  @@ -42,14 +65,14 @@
   		setTitle(description); 
   		Composite control = (Composite) super.createDialogArea( parent );
   		
  -		Composite composite = new Composite(control,SWT.NONE);
  -		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
  -		GridLayout layout = new GridLayout(3,false);
  +		Composite defaultComposite = new Composite(control,SWT.NONE);
  +		defaultComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
  +		GridLayout layout = new GridLayout(4,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);
  +        defaultComposite.setLayout(layout);
           
           ModifyListener modifyListener = new ModifyListener() {
   			
  @@ -59,33 +82,124 @@
   		
   		};
   
  +		Map groupContainers = new HashMap();
  +		if(!groups.isEmpty()) {
  +			
  +			TabFolder folder = new TabFolder(defaultComposite,SWT.TOP);
  +			folder.setLayoutData( new GridData(GridData.FILL_BOTH ));
  +			Iterator iterator = groups.iterator();
  +			while ( iterator.hasNext() ) {
  +				String name = (String) iterator.next();
  +				TabItem item = new TabItem(folder, SWT.NONE);
  +				item.setText( name );
  +				
  +				Composite container = new Composite(folder, SWT.NULL);
  +				GridLayout gridLayout = new GridLayout(4, false);
  +				//gridLayout.verticalSpacing = 9;		
  +				
  +				container.setLayout(gridLayout);
  +				item.setControl( container );
  +				groupContainers.put(name, container);					
  +			}
  +		}
  +		
   		Map properties = questions;
   		
  +		Properties existing = new Properties();
  +		ILaunchConfiguration configuration;
  +		try {
  +			configuration = SeamGenAction.findLaunchConfig( "seamgen" );
  +			if(configuration!=null) {
  +				existing = SeamGenAction.getSeamGenProperties( configuration );
  +			}
  +			
  +		}
  +		catch (CoreException e1) {
  +			SeamGenPlugin.logError( "Error while preloading build.properties", e1 );
  +		}
  +		
  +		updating = true;
   		Text firstField = null;
   		Iterator iterator = properties.entrySet().iterator();
   		while ( iterator.hasNext() ) {
   			Map.Entry element = (Map.Entry) iterator.next();
   			String name = (String) element.getKey();
  -			SeamGenProperty sgp = (SeamGenProperty) element.getValue();
  +			final SeamGenProperty sgp = (SeamGenProperty) element.getValue();
   		
  +			Composite composite = (Composite) groupContainers.get(sgp.getGroup());
  +			if(composite==null) {
  +				composite = defaultComposite;
  +			}
   			Label label = new Label(composite, SWT.NONE);
   			label.setText( sgp.getDescription() + ":" );
   			
  -			Text text = new Text(composite, SWT.BORDER | SWT.LEAD);
  -			text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
  +			
  +			
  +			if(sgp.getInputType()==sgp.YES_NO) {
  +				Button button = new Button(composite, SWT.CHECK);
  +				propertyToField.put( name, button );
  +				sgp.applyValue( existing, button );
  +				GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
  +				data.horizontalSpan= 2;
  +				button.setLayoutData(data);
  +			} else {
  +				final Text text = new Text(composite, SWT.BORDER | SWT.LEAD);
   			text.setFocus();
   			text.addModifyListener( modifyListener );
   			if(firstField==null) {
   				firstField = text;
   			}
   			propertyToField.put(name, text);
  +				sgp.applyValue( existing, text );
  +				if(sgp.getInputType()==sgp.JAR || sgp.getInputType()==sgp.DIR) {
  +					GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
  +					data.horizontalSpan= 1;
  +					text.setLayoutData(data);
  +
  +					Button button = new Button(composite, SWT.PUSH);
  +					button.setText("Browse...");
  +					button.addSelectionListener(new SelectionAdapter() {
  +						public void widgetSelected(SelectionEvent e) {
  +							String paths = null;
  +							switch(sgp.getInputType()) {
  +							case SeamGenProperty.JAR:
  +								paths = chooseExternalFile(getShell() );
  +								break;
  +							case SeamGenProperty.DIR:	
  +								paths = chooseExternalDirectory( getShell() );
  +								break;
  +							default:
  +								paths = null;
  +							}
  +
  +							if(paths!=null) {
  +								text.setText(paths);
  +							}
  +
  +						}
  +					});
  +				} else {
  +					GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
  +					data.horizontalSpan = 2;
  +					text.setLayoutData(data);
   			
  +				}
  +			}
   			label = new Label(composite, SWT.NONE);
  +			label.setVisible(false);
   			label.setText( "                       " );
  +			
   			propertyToDefaultLabel.put( name, label );
  +			updating = false;
  +			//updateStatus();
   			
   		}
   		
  +		
  +		Label label = new Label(defaultComposite, SWT.NONE); // here to make gtk less ugly.
  +		//label.setText( "--------------" );
  +		
  +		
   		firstField.setFocus();
   		//initDefaultNames(ef, propertyCombo);
   		
  @@ -93,6 +207,25 @@
   	}
   
   	
  +	protected String chooseExternalFile(Shell shell) {
  +		FileDialog dialog= new FileDialog(shell, SWT.SINGLE);
  +		dialog.setText("Select file"); 
  +		dialog.setFilterExtensions(new String[] {"*.jar;*.zip"});
  +		//dialog.setFilterPath(lastUsedPath);
  +		
  +		String res= dialog.open();
  +		
  +		return res;
  +		}
  +
  +	protected String chooseExternalDirectory(Shell shell) {
  +		DirectoryDialog dialog= new DirectoryDialog(shell, SWT.SINGLE);
  +		dialog.setText("Select directory"); 
  +		
  +		String res= dialog.open();
  +		return res;			
  +	}
  +
   	public Map getPropertiesResult() {
   		return result;
   	}
  @@ -102,19 +235,48 @@
   		Iterator iterator = propertyToField.entrySet().iterator();
   		while ( iterator.hasNext() ) {
   			Map.Entry element = (Map.Entry) iterator.next();
  +			Object value = element.getValue();
  +			
  +			String text;
  +			if(value instanceof Text) {
   			Text t = (Text) element.getValue();
  +				text = t.getText();
  +			} else {
  +				Button t = (Button) element.getValue();
  +				if(t.getSelection()) {
  +					text = "y";
  +				} else {
  +					text = "n";
  +				}
  +			}
  +			SeamGenProperty sgp = (SeamGenProperty) questions.get( element.getKey() );
   			
   			
  -			String text = t.getText();
  -			if(text.trim().length()>0) {
  +			if(!sgp.isRequired() || text.trim().length()>0) {
   				m.put( element.getKey(), text);	
   			} else {
   				Label dv = (Label) propertyToDefaultLabel.get(element.getKey());
  -				if(dv.getText().trim().length()>0) {
  -					m.put( element.getKey(), dv.getText());
  +				String text2 = dv.getText();
  +				if(text2.trim().length()>0) {
  +					m.put( element.getKey(), text2);
   				}
   			}
  +			
  +			//			hack to make sure seamgen does not mess with the path names.
  +			switch(sgp.getInputType()) {
  +			case SeamGenProperty.DIR:
  +			case SeamGenProperty.JAR:
  +				String str = (String) m.get( element.getKey() );
  +				if(str!=null) {
  +					m.put( element.getKey(), str.replace('\\', '/'));
  +				}
  +				break;
  +			default: 
  +				break;
  +			}
  +			
   		}
  +		
   		return m;
   	}
   
  @@ -140,12 +302,21 @@
   				String defaultValue = gp.getDefaultValue( properties );
   				text.setText( defaultValue==null?"":defaultValue );
   				
  -				Text enteredValue = (Text) propertyToField.get(element.getKey());
  -				if(haveNoWarning && enteredValue.getText().trim().length()==0 && text.getText().trim().length()==0 ) {
  -					setMessage( gp.getDescription() + " requires a value", IMessageProvider.ERROR );
  +				String text2 = getText( element, text );
  +				
  +				if(haveNoWarning) {					
  +					String msg = gp.valid(text2.trim());
  +					if(text2.trim().length()>0 && msg!=null) {
  +						setMessage( msg, IMessageProvider.ERROR );
  +						haveNoWarning = false;
  +						getButton( IDialogConstants.OK_ID ).setEnabled( false );
  +					} else if(gp.isRequired() && text2.trim().length()==0 && text.getText().trim().length()==0 ) {
  +						setMessage( "'" + gp.getDescription() + "' requires a value", IMessageProvider.ERROR );
   					haveNoWarning = false;
   					getButton( IDialogConstants.OK_ID ).setEnabled( false );
   				}
  +				}
  +				
   				
   			}
   			updating = false;
  @@ -172,6 +343,24 @@
   		}*/
   	}
   	
  +	private String getText(Map.Entry element, Label text) {
  +		Control object = (Control) propertyToField.get(element.getKey());
  +		if(object instanceof Button) {
  +			Button b = (Button) object;
  +			b.setToolTipText( text.getText() );
  +			if(b.getSelection()) {
  +				return "y";
  +			} else {
  +				return "n";
  +			}
  +			
  +		} else {
  +			Text enteredValue = (Text) object;
  +			enteredValue.setToolTipText( text.getText() );
  +			return enteredValue.getText();
  +		}
  +	}
  +	
   	protected void okPressed() {
   		result = internalGetResult();
   		super.okPressed();		
  @@ -182,4 +371,6 @@
   		super.create();
   		updateStatus();
   	}
  +	
  +	
   }
  
  
  
  1.2       +61 -1     jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SeamGenProperty.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/seam/plugins/org.jboss.ide.seam.gen/src/org/jboss/ide/seam/gen/SeamGenProperty.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- SeamGenProperty.java	15 Feb 2007 12:20:44 -0000	1.1
  +++ SeamGenProperty.java	14 Mar 2007 09:21:29 -0000	1.2
  @@ -2,12 +2,33 @@
   
   import java.util.Properties;
   
  +import org.eclipse.swt.widgets.Button;
  +import org.eclipse.swt.widgets.Control;
  +import org.eclipse.swt.widgets.Text;
  +
   public class SeamGenProperty {
   
   	private final String description;
   
  +	private String defaultPropertyName;
  +
  +	public static final String GENERAL = "General";
  +	public final static int TEXT = 0;
  +	public final static int JAR = 1;
  +	public final static int DIR = 2;
  +	public final static int YES_NO = 3;
  +	
   	public SeamGenProperty(String description) {
  +		this(description, null);
  +	}
  +	
  +	public SeamGenProperty(String description, String defaultPropertyName) {
   		this.description = description;
  +			this.defaultPropertyName = defaultPropertyName;
  +	}
  +
  +	public String getGroup() {
  +		return GENERAL;
   	}
   
   	public String getDescription() {
  @@ -29,4 +50,43 @@
   			return "";
   		return name.substring( 0, 1 ).toLowerCase() + name.substring( 1 );
   	}
  +	
  +	public boolean isRequired() {
  +		return true;
  +	}
  +
  +	public int getInputType() {
  +		return TEXT;
  +	}
  +
  +	public String valid(String string) {
  +		return null;
  +	}
  +	
  +	
  +	public void applyValue(Properties existing, Control control) {
  +		try {
  +			String property = existing.getProperty( getDefaultPropertyName() );
  +			if(property!=null) {
  +				if(control instanceof Text) {
  +					((Text)control).setText( property );
  +				} else if (control instanceof Button) {
  +					if("y".equalsIgnoreCase( property )) {
  +						((Button)control).setSelection( true );
  +					} else {
  +						((Button)control).setSelection( false );
  +					}
  +				} else {
  +					System.out.println(getDefaultPropertyName() + " " + property);
  +				}
  +			}
  +		} catch(Exception e) {
  +			e.printStackTrace();
  +		}
  +
  +	}
  +
  +	public String getDefaultPropertyName() {
  +		return defaultPropertyName;
  +	}
   }
  
  
  



More information about the jboss-cvs-commits mailing list