[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch ...

Max Rydahl Andersen mandersen at jboss.com
Thu Aug 10 03:01:51 EDT 2006


  User: mandersen
  Date: 06/08/10 03:01:51

  Modified:    hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch       
                        ExporterSettings.java
                        LaunchConfigurationTabGroup.java
                        ExporterAttributes.java
                        CodeGenerationLaunchDelegate.java
  Added:       hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch       
                        ICodeGenerationLaunchConstants.java
                        AddPropertyDialog.java
                        ExporterFactoryPropertySource.java
  Log:
  customizing properties for exporter
  
  Revision  Changes    Path
  1.11      +303 -121  jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExporterSettings.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettings.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- ExporterSettings.java	7 Jul 2006 13:51:08 -0000	1.10
  +++ ExporterSettings.java	10 Aug 2006 07:01:51 -0000	1.11
  @@ -36,15 +36,18 @@
   import org.eclipse.debug.core.ILaunchConfiguration;
   import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
   import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
  -import org.eclipse.jdt.internal.ui.preferences.ScrolledPageContent;
  +import org.eclipse.jface.dialogs.Dialog;
   import org.eclipse.jface.dialogs.IDialogPage;
  -import org.eclipse.jface.resource.JFaceResources;
   import org.eclipse.jface.viewers.CheckStateChangedEvent;
   import org.eclipse.jface.viewers.CheckboxTableViewer;
   import org.eclipse.jface.viewers.ICheckStateListener;
   import org.eclipse.jface.viewers.ILabelProviderListener;
  +import org.eclipse.jface.viewers.ISelection;
  +import org.eclipse.jface.viewers.ISelectionChangedListener;
   import org.eclipse.jface.viewers.IStructuredContentProvider;
  +import org.eclipse.jface.viewers.IStructuredSelection;
   import org.eclipse.jface.viewers.ITableLabelProvider;
  +import org.eclipse.jface.viewers.SelectionChangedEvent;
   import org.eclipse.jface.viewers.Viewer;
   import org.eclipse.swt.SWT;
   import org.eclipse.swt.events.SelectionAdapter;
  @@ -56,14 +59,21 @@
   import org.eclipse.swt.widgets.Button;
   import org.eclipse.swt.widgets.Composite;
   import org.eclipse.swt.widgets.Control;
  +import org.eclipse.swt.widgets.Group;
  +import org.eclipse.swt.widgets.Label;
   import org.eclipse.swt.widgets.Table;
  -import org.eclipse.ui.forms.events.ExpansionAdapter;
  -import org.eclipse.ui.forms.events.ExpansionEvent;
  -import org.eclipse.ui.forms.widgets.ExpandableComposite;
  +import org.eclipse.ui.views.properties.IPropertyDescriptor;
  +import org.eclipse.ui.views.properties.IPropertySheetEntry;
  +import org.eclipse.ui.views.properties.IPropertySheetEntryListener;
  +import org.eclipse.ui.views.properties.IPropertySource;
  +import org.eclipse.ui.views.properties.IPropertySourceProvider;
  +import org.eclipse.ui.views.properties.PropertySheetEntry;
  +import org.eclipse.ui.views.properties.PropertySheetPage;
   import org.hibernate.console.ImageConstants;
   import org.hibernate.eclipse.console.ExtensionManager;
   import org.hibernate.eclipse.console.HibernateConsolePlugin;
   import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
  +import org.hibernate.eclipse.console.model.impl.ExporterFactory;
   import org.hibernate.eclipse.console.utils.EclipseImages;
   
   public class ExporterSettings extends AbstractLaunchConfigurationTab {
  @@ -71,19 +81,20 @@
   
   	private Button enableJDK5;
   
  -	
  -	private ExpansionListener expansionListener = new ExpansionListener();
  -
   	private List selectedExporters;
   
   	private CheckboxTableViewer exporterTable;
   
  -	private ExporterDefinition[] exporters;
  -
   	private Button selectAll;
   
   	private Button deselectAll;
   
  +	private PropertySheetPage propertySheet;
  +
  +	private Button add;
  +
  +	private Button remove;
  +
   	/**
   	 * Constructor for SampleNewWizardPage.
   	 * 
  @@ -98,44 +109,191 @@
   	 */
   	public void createControl(Composite parent) {
   		selectedExporters = new ArrayList();
  -		exporters = ExtensionManager.findExporterDefinitions();
   
  -		// initializeDialogUnits(parent);
  -		ScrolledPageContent sc = new ScrolledPageContent( parent );
  -		Composite container = sc.getBody();
  -		// Composite container = new Composite(parent, SWT.NULL);
  -		GridLayout layout = new GridLayout();
  -		layout.marginHeight = 0;
  -		layout.marginWidth = 0;
  +		// ScrolledComposite scrolled = new ScrolledComposite(parent,
  +		// SWT.V_SCROLL | SWT.H_SCROLL);
  +
  +		Composite container = new Composite( parent, SWT.NONE );
  +		GridData controlData = new GridData( GridData.FILL_BOTH );
  +		container.setLayoutData( controlData );
   
  +		GridLayout layout = new GridLayout();
  +		layout.marginHeight = 5;
  +		layout.marginWidth = 5;
  +		layout.verticalSpacing = 1;
   		container.setLayout( layout );
  -		// layout.numColumns = 1;
  -		// layout.verticalSpacing = 10;
   
  -		SelectionListener fieldlistener = new SelectionListener() {
  -			public void widgetDefaultSelected(SelectionEvent e) {
  -				widgetSelected( e );
  +		createGeneralSettings( container );
  +
  +		createExporterTable( container );
  +
  +		createExporterProperties( container );
  +
  +		dialogChanged();
  +		setControl( container );
  +	}
  +
  +	private void createExporterProperties(Composite parent) {
  +		Composite exportersComposite = createComposite( parent, "Properties:" );
  +
  +		exportersComposite.setLayout( new GridLayout( 2, false ) );
  +
  +		GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
  +		gd.minimumHeight = 100;
  +		exportersComposite.setLayoutData( gd );
  +
  +		Group gr = new Group(exportersComposite, SWT.NONE);
  +		
  +		GridLayout gridLayout = new GridLayout();
  +		gridLayout.marginHeight = 0;
  +		gridLayout.marginWidth = 0;
  +		
  +		gr.setLayout( gridLayout );		
  +		gd = new GridData( SWT.FILL, SWT.FILL, true, true );
  +		gd.verticalSpan = 2;		
  +		gr.setLayoutData( gd );
  +
  +		Control sheet = createPropertySheet( gr );
  +		gd = new GridData( SWT.FILL, SWT.FILL, true, true );		
  +		sheet.setLayoutData( gd );
  +		
  +		add = new Button( exportersComposite, SWT.PUSH );
  +		add.setEnabled( false );
  +		add.setText( "Add..." );
  +		gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
  +				| GridData.VERTICAL_ALIGN_BEGINNING );
  +		gd.horizontalIndent = 5;
  +		add.setLayoutData( gd );
  +		add.addSelectionListener( new SelectionAdapter() {
  +		
  +			public void widgetSelected(SelectionEvent e) {
  +				IStructuredSelection ss = (IStructuredSelection) exporterTable.getSelection();
  +				ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
  +
  +				if(ef!=null) {
  +					AddPropertyDialog dialog = new AddPropertyDialog(getShell(), ef);
  +					if(dialog.open()==Dialog.OK) {
  +						ef.setProperty( dialog.getPropertyName(), dialog.getPropertyValue() );
  +						dialogChanged();	
  +						refreshPropertySheet();
  +					}
  +				}
   			}
   
  +		} );
  +
  +		remove = new Button( exportersComposite, SWT.PUSH );
  +		remove.setText( "Remove..." );
  +		remove.setEnabled( false );
  +		remove.addSelectionListener( new SelectionAdapter() {
  +		
   			public void widgetSelected(SelectionEvent e) {
  +				if(currentDescriptor!=null) {
  +					IStructuredSelection ss = (IStructuredSelection) exporterTable.getSelection();
  +					ExporterFactory ef = (ExporterFactory) ss.getFirstElement();
  +					ef.removeProperty( (String) currentDescriptor.getId() );
   				dialogChanged();
  +					refreshPropertySheet();
  +				}				
  +			}
  +		
  +		} );
  +		
  +		gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
  +				| GridData.VERTICAL_ALIGN_BEGINNING );
  +		gd.horizontalIndent = 5;
  +		remove.setLayoutData( gd );
  +
  +	}
  +
  +	public class MyPropertySheetEntry extends PropertySheetEntry {
  +		
  +		public IPropertyDescriptor getMyDescriptor() {
  +			return super.getDescriptor();
  +		}
  +		
  +		protected PropertySheetEntry createChildEntry() {
  +			return new MyPropertySheetEntry();
  +		}
  +	}
  +	
  +	// currently selected in the propertysheet
  +	private IPropertyDescriptor currentDescriptor;
  +	
  +	private Control createPropertySheet(Composite exportersComposite) {
  +		propertySheet = new PropertySheetPage() {
  +			
  +
  +			public void handleEntrySelection(ISelection selection) {
  +				super.handleEntrySelection( selection );
  +				IStructuredSelection iss = (IStructuredSelection) selection;
  +				if(iss.isEmpty()) {
  +					currentDescriptor = null;
  +				} else {
  +					MyPropertySheetEntry mse = (MyPropertySheetEntry)iss.getFirstElement();
  +					currentDescriptor = mse.getMyDescriptor();
  +				}
   			}
   		};
   
  -		Composite generalSettingsComposite = createExpandableComposite(
  -				container, "General settings", true );
  -		Composite exportersComposite = createExpandableComposite( container,
  -				"Exporters", true );
  +		propertySheet.createControl( exportersComposite );
   
  -		enableJDK5 = new Button( generalSettingsComposite, SWT.CHECK );
  -		enableJDK5.setText( "Use Java 5 syntax" );
  -		enableJDK5.addSelectionListener( fieldlistener );
  +		final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
   
  -		enableEJB3annotations = new Button( generalSettingsComposite, SWT.CHECK );
  -		enableEJB3annotations.setText( "Generate EJB3 annotations" );
  -		enableEJB3annotations.addSelectionListener( fieldlistener );
  +		propertySheetEntry
  +				.setPropertySourceProvider( new IPropertySourceProvider() {
  +
  +					public IPropertySource getPropertySource(Object object) {
  +						if ( object instanceof ExporterFactory ) {
  +							return new ExporterFactoryPropertySource(
  +									(ExporterFactory) object ) {
  +								public void setPropertyValue(Object id, Object value) {
  +									super.setPropertyValue( id, value );
  +									dialogChanged();
  +								}
  +							};
  +						}
  +						else {
  +							return null;
  +						}
  +					}
  +				} );
  +		propertySheet.setRootEntry( propertySheetEntry );
  +		// propertySheetEntry.setValues( new Object[] { this });
  +		
  +		exporterTable
  +				.addSelectionChangedListener( new ISelectionChangedListener() {
  +
  +					public void selectionChanged(SelectionChangedEvent event) {
  +						IStructuredSelection s = (IStructuredSelection) event
  +						.getSelection();
  +						if(s.isEmpty()) {
  +							if(add!=null) add.setEnabled( false );
  +							if(remove!=null) remove.setEnabled( false );		
  +					
  +						} else {
  +							if(add!=null) add.setEnabled( true );
  +							if(remove!=null) remove.setEnabled( true );		
  +					
  +							ExporterFactory ep = (ExporterFactory) s
  +							.getFirstElement();
  +							propertySheetEntry.setValues( new Object[] { ep } );
  +							// if(ep.isEnabled( configuration ))
  +						}
  +					}
  +
  +				} );
  +
  +		return propertySheet.getControl();
  +	}
  +
  +	private void createExporterTable(Composite parent) {
  +		Composite exporterOptions = createComposite( parent, "Exporters:" );
  +
  +		GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
  +		gd.minimumHeight = 100;
  +		exporterOptions.setLayoutData( gd );
   
  -		Composite exporterOptions = new Composite( exportersComposite, SWT.NONE );
   		exporterOptions.setLayout( new GridLayout( 2, false ) );
   		
   		Table table = new Table( exporterOptions, SWT.CHECK | SWT.BORDER
  @@ -143,32 +301,34 @@
   		exporterTable = new CheckboxTableViewer( table );
   		exporterTable.setContentProvider( new ExporterContentProvider() );
   		exporterTable.setLabelProvider( new ExporterLabelProvider() );
  -		exporterTable.setInput( exporters );
  -		exporterTable.getControl().setLayoutData(
  -				new GridData( SWT.FILL, SWT.FILL, true, true ) );
  +		
  +		// exporterTable.getControl().setLayoutData(
  +		// new GridData( SWT.FILL, SWT.FILL, true, true ) );
   		exporterTable.setColumnProperties( new String[] { "", "Description" } );
   		exporterTable.addCheckStateListener( new ICheckStateListener() {
   			public void checkStateChanged(CheckStateChangedEvent event) {
  -				ExporterDefinition definition = (ExporterDefinition) event
  -						.getElement();
   
  -				if ( !event.getChecked() && selectedExporters.contains( definition ) ) {
  -					selectedExporters.remove( definition );
  -				} else if ( event.getChecked() && !selectedExporters.contains( definition ) ) {
  -					selectedExporters.add( definition );
  +				ExporterFactory factory = (ExporterFactory) event.getElement();
  +
  +				if ( !event.getChecked()
  +						&& selectedExporters.contains( factory ) ) {
  +					selectedExporters.remove( factory );
  +				}
  +				else if ( event.getChecked()
  +						&& !selectedExporters.contains( factory ) ) {
  +					selectedExporters.add( factory );
   				}
   
   				dialogChanged();
   			}
   		} );
   
  -		Composite listActionsComposite = new Composite( exporterOptions,
  -				SWT.NONE );
  -		listActionsComposite.setLayout( new GridLayout( 1, true ) );
  -		listActionsComposite.setLayoutData( new GridData( SWT.FILL, SWT.FILL,
  -				true, true ) );
  +		gd = new GridData( SWT.FILL, SWT.FILL, true, true );
  +		gd.verticalSpan = 2;
  +		gd.horizontalSpan = 1;
  +		table.setLayoutData( gd );
   
  -		selectAll = new Button( listActionsComposite, SWT.PUSH );
  +		selectAll = new Button( exporterOptions, SWT.PUSH );
   		selectAll.setText( "Select All" );
   		selectAll.addSelectionListener( new SelectionAdapter() {
   			public void widgetSelected(SelectionEvent e) {
  @@ -176,8 +336,12 @@
   				dialogChanged();
   			}
   		} );
  +		gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
  +				| GridData.VERTICAL_ALIGN_BEGINNING );
  +		gd.horizontalIndent = 5;
  +		selectAll.setLayoutData( gd );
   
  -		deselectAll = new Button( listActionsComposite, SWT.PUSH );
  +		deselectAll = new Button( exporterOptions, SWT.PUSH );
   		deselectAll.setText( "Deselect All" );
   		deselectAll.addSelectionListener( new SelectionAdapter() {
   			public void widgetSelected(SelectionEvent e) {
  @@ -186,14 +350,42 @@
   			}
   		} );
   
  +		gd = new GridData( GridData.HORIZONTAL_ALIGN_FILL
  +				| GridData.VERTICAL_ALIGN_BEGINNING );
  +		gd.horizontalIndent = 5;
  +		deselectAll.setLayoutData( gd );
  +
  +	}
  +
  +	private void createGeneralSettings(Composite parent) {
  +
  +		SelectionListener fieldlistener = new SelectionListener() {
  +			public void widgetDefaultSelected(SelectionEvent e) {
  +				widgetSelected( e );
  +			}
  +
  +			public void widgetSelected(SelectionEvent e) {
   		dialogChanged();
  -		setControl( sc );
  +			}
  +		};
  +		Composite generalSettingsComposite = createComposite( parent,
  +				"General settings:" );
  +		generalSettingsComposite.setLayoutData( new GridData( SWT.BEGINNING,
  +				SWT.BEGINNING, false, false ) );
  +
  +		enableJDK5 = new Button( generalSettingsComposite, SWT.CHECK );
  +		enableJDK5.setText( "Use Java 5 syntax" );
  +		enableJDK5.addSelectionListener( fieldlistener );
  +
  +		enableEJB3annotations = new Button( generalSettingsComposite, SWT.CHECK );
  +		enableEJB3annotations.setText( "Generate EJB3 annotations" );
  +		enableEJB3annotations.addSelectionListener( fieldlistener );
   	}
   
   	private class ExporterContentProvider implements IStructuredContentProvider {
   
   		public Object[] getElements(Object inputElement) {
  -			return (Object[]) inputElement;
  +			return ((List) inputElement ).toArray();
   		}
   
   		public void dispose() {
  @@ -206,10 +398,12 @@
   
   	private class ExporterLabelProvider implements ITableLabelProvider {
   		Map exp2img = new HashMap(); // not the most optimized but better
  +
   										// than having a finalize method.
   
   		public Image getColumnImage(Object element, int columnIndex) {
  -			ExporterDefinition definition = (ExporterDefinition) element;
  +			ExporterFactory ef = (ExporterFactory) element;
  +			ExporterDefinition definition = ef.getExporterDefinition();
   			Image image = (Image) exp2img.get( definition.getId() );
   			if ( image == null ) {
   				image = definition.getIconDescriptor().createImage();
  @@ -219,7 +413,8 @@
   		}
   
   		public String getColumnText(Object element, int columnIndex) {
  -			ExporterDefinition definition = (ExporterDefinition) element;
  +			ExporterFactory ef = (ExporterFactory) element;
  +			ExporterDefinition definition = ef.getExporterDefinition();
   			return definition.getDescription();
   		}
   
  @@ -246,61 +441,21 @@
   
   	}
   
  -	private Composite createExpandableComposite(Composite parent, String name,
  -			boolean expanded) {
  -		ExpandableComposite composite = new ExpandableComposite( parent,
  -				SWT.NONE, ExpandableComposite.CLIENT_INDENT
  -						| ExpandableComposite.TWISTIE );
  -		composite.setExpanded( expanded );
  -		composite.setText( name );
  -		composite.setFont( JFaceResources.getFontRegistry().getBold(
  -				JFaceResources.DEFAULT_FONT ) );
  -		composite.setLayout( new GridLayout( 1, false ) );
  -		composite
  -				.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, false ) );
  -		composite.addExpansionListener( expansionListener );
  -		ScrolledPageContent scrolledParent = getExpandableCompositeParent( composite );
  -		if ( scrolledParent != null )
  -			scrolledParent.adaptChild( composite );
  -
  -		Composite client = new Composite( composite, SWT.NONE );
  -		composite.setClient( client );
  -		client.setLayout( new GridLayout( 1, false ) );
  -		client.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
  +	private Composite createComposite(Composite parent, String name) {
   
  +		new Label( parent, SWT.NONE ).setText( name );
  +		Composite client = new Composite( parent, SWT.NONE );
  +		client.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
  +		client.setLayout( new GridLayout() );
  +		// client.setBackground( ColorConstants.cyan );
   		return client;
   	}
   
  -	private class ExpansionListener extends ExpansionAdapter {
  -
  -		public void expansionStateChanged(ExpansionEvent e) {
  -			ScrolledPageContent parent = getExpandableCompositeParent( (ExpandableComposite) e
  -					.getSource() );
  -			if ( parent != null )
  -				parent.reflow( true );
  -
  -			((ExpandableComposite) e.getSource() ).redraw();
  -		}
  -	}
  -
  -	private ScrolledPageContent getExpandableCompositeParent(
  -			ExpandableComposite composite) {
  -		Control parent = composite.getParent();
  -		while ( !(parent instanceof ScrolledPageContent ) && parent != null )
  -			parent = parent.getParent();
  -
  -		if ( parent instanceof ScrolledPageContent )
  -			return (ScrolledPageContent) parent;
  -		else
  -			return null;
  -	}
  -
   	private void dialogChanged() {
   		boolean configSelected = true; // TODO: only active if configname in
   										// settings
   										// ...getConfigurationName().length()==0;
   
  -		
   		if ( !configSelected ) {
   			updateStatus( "Console configuration must be specified" );
   			return;
  @@ -373,22 +528,28 @@
   
   	public void initializeFrom(ILaunchConfiguration configuration) {
   		try {
  -			ExporterAttributes attributes = new ExporterAttributes( configuration );
  +			ExporterAttributes attributes = new ExporterAttributes(
  +					configuration );
   			selectedExporters.clear();
   
   			enableEJB3annotations.setSelection( attributes.isEJB3Enabled() );
   			enableJDK5.setSelection( attributes.isJDK5Enabled() );
   
  -			for (int i = 0; i < exporters.length; i++) {
  -				if ( exporters[i].isEnabled( configuration ) ) {
  -					exporterTable.setChecked( exporters[i], true );
  -					selectedExporters.add( exporters[i] );
  +			List exporterFactories = attributes.getExporterFactories();
  +			exporterTable.setInput( exporterFactories );
  +			for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
  +				ExporterFactory exporterFactory = (ExporterFactory) iter.next();
  +				if ( exporterFactory.isEnabled() ) {
  +					exporterTable.setChecked( exporterFactory, true );
  +					selectedExporters.add( exporterFactory );
   				}
   				else {
  -					exporterTable.setChecked( exporters[i], false );
  +					exporterTable.setChecked( exporterFactory, false );
   				}
   			}			
   
  +			refreshPropertySheet();
  +			
   			dialogChanged();
   
   		}
  @@ -401,15 +562,36 @@
   		}
   	}
   
  +	private void refreshPropertySheet() {
  +		exporterTable.setSelection( exporterTable.getSelection() ); // here to make sure the dependent propertysheet actually will reread what ever the selection is.
  +	}
  +
   	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
  -		configuration.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, enableEJB3annotations.getSelection());
  -		configuration.setAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5, enableJDK5.getSelection() );
  +		configuration.setAttribute(
  +				HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,
  +				enableEJB3annotations.getSelection() );
  +		configuration.setAttribute( HibernateLaunchConstants.ATTR_ENABLE_JDK5,
  +				enableJDK5.getSelection() );
   
  -		for (int i = 0; i < exporters.length; i++) {
  -			ExporterDefinition exporterDefinition = exporters[i];
  -			boolean enabled = selectedExporters.contains( exporterDefinition );
  -			exporterDefinition.setEnabled( configuration, enabled );
  +		List exporterFactories = (List) exporterTable.getInput();
  +		for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
  +			ExporterFactory ef = (ExporterFactory) iter.next();
  +			boolean enabled = selectedExporters.contains( ef );
  +			
  +			String propertiesId = ef.getId() + ".properties";
  +			
  +			ef.setEnabled( configuration, enabled );
  +			
  +				
  +			HashMap map = new HashMap(ef.getProperties());
  +
  +			if(map.isEmpty()) {				
  +				configuration.setAttribute( propertiesId, (Map)null );
  +			} else {
  +				configuration.setAttribute( propertiesId, map );
  +			}		
   		}
  +		
   	}
   
   	public String getName() {
  
  
  
  1.4       +0 -1      jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LaunchConfigurationTabGroup.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/LaunchConfigurationTabGroup.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- LaunchConfigurationTabGroup.java	7 Jul 2006 13:51:08 -0000	1.3
  +++ LaunchConfigurationTabGroup.java	10 Aug 2006 07:01:51 -0000	1.4
  @@ -38,7 +38,6 @@
   		ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
   				new CodeGenerationSettings(),
   				new ExporterSettings(),
  -				//new ExporterProvidersTab(),
   				new RefreshTab(),
   				new CommonTab()
   			};
  
  
  
  1.5       +27 -1     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExporterAttributes.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ExporterAttributes.java	7 Jul 2006 13:51:08 -0000	1.4
  +++ ExporterAttributes.java	10 Aug 2006 07:01:51 -0000	1.5
  @@ -40,10 +40,18 @@
    */
   package org.hibernate.eclipse.launch;
   
  +import java.util.ArrayList;
  +import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
  +
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.Path;
   import org.eclipse.debug.core.ILaunchConfiguration;
  +import org.hibernate.eclipse.console.ExtensionManager;
   import org.hibernate.eclipse.console.HibernateConsolePlugin;
  +import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
  +import org.hibernate.eclipse.console.model.impl.ExporterFactory;
   
   // This class was created to centralize launch configuration attribute loading/saving
   // (and also to clean up CodeGenerationLaunchDelegate considerably)
  @@ -56,6 +64,7 @@
      private String packageName;
      private String outputPath;
      private String templatePath;
  +   private List exporterFactories;
      
      public ExporterAttributes () { }
   
  @@ -85,6 +94,19 @@
           	 templatePath = null;
            }
            
  +         ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
  +
  + 		exporterFactories = new ArrayList();
  + 		for (int i = 0; i < exDefinitions.length; i++) {
  + 			ExporterDefinition expDef = exDefinitions[i];
  + 			ExporterFactory exporterFactory = new ExporterFactory( expDef );
  + 			exporterFactory.isEnabled( configuration );
  +			exporterFactories.add( exporterFactory );
  +			Map props = configuration.getAttribute( exporterFactory.getId()
  +					+ ".properties", new HashMap() );
  +			exporterFactory.setProperties( props );
  + 		}
  + 		
         } catch (CoreException e) {
            throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666)); 
         }
  @@ -209,6 +231,10 @@
         this.useOwnTemplates = useOwnTemplates;
      }
   
  +   public List getExporterFactories() {
  +	   return exporterFactories;	
  +   }
  +
      
   
      
  
  
  
  1.16      +40 -12    jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CodeGenerationLaunchDelegate.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- CodeGenerationLaunchDelegate.java	12 Jul 2006 10:03:27 -0000	1.15
  +++ CodeGenerationLaunchDelegate.java	10 Aug 2006 07:01:51 -0000	1.16
  @@ -24,6 +24,7 @@
   import java.io.File;
   import java.lang.reflect.Constructor;
   import java.util.ArrayList;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   import java.util.Properties;
  @@ -39,8 +40,10 @@
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IPath;
   import org.eclipse.core.runtime.IProgressMonitor;
  +import org.eclipse.core.runtime.IStatus;
   import org.eclipse.core.runtime.OperationCanceledException;
   import org.eclipse.core.runtime.Path;
  +import org.eclipse.core.runtime.Status;
   import org.eclipse.debug.core.ILaunch;
   import org.eclipse.debug.core.ILaunchConfiguration;
   import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
  @@ -66,9 +69,11 @@
   import org.hibernate.eclipse.console.ExtensionManager;
   import org.hibernate.eclipse.console.HibernateConsolePlugin;
   import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
  +import org.hibernate.eclipse.console.model.impl.ExporterFactory;
   import org.hibernate.tool.hbm2x.ArtifactCollector;
   import org.hibernate.tool.hbm2x.Exporter;
   import org.hibernate.util.ReflectHelper;
  +import org.hibernate.util.StringHelper;
   
   public class CodeGenerationLaunchDelegate extends
   		LaunchConfigurationDelegate {
  @@ -116,16 +121,15 @@
   		try {
   		    ExporterAttributes attributes = new ExporterAttributes(configuration);
               
  -            ExporterDefinition exporters[] = ExtensionManager.findExporterDefinitions();
  -            List exporterArray = new ArrayList();
  -            for (int i = 0; i < exporters.length; i++)
  -            {
  -               if (exporters[i].isEnabled(configuration)) {
  -                  exporterArray.add(exporters[i]);
  +		    List exporterFactories = attributes.getExporterFactories();
  +		    for (Iterator iter = exporterFactories.iterator(); iter.hasNext();) {
  +				ExporterFactory exFactory = (ExporterFactory) iter.next();
  +				if(!exFactory.isEnabled(configuration)) {
  +					iter.remove();
                  }
               }
               
  -            exporters = (ExporterDefinition []) exporterArray.toArray(new ExporterDefinition[exporterArray.size()]);
  +		    ExporterFactory[] exporters = (ExporterFactory[]) exporterFactories.toArray( new ExporterFactory[exporterFactories.size()] );
               ArtifactCollector collector = runExporters(attributes, exporters, monitor);
   			refreshOutputDir( attributes.getOutputPath() );
   
  @@ -192,7 +196,7 @@
   		}
   	}
   
  -	private ArtifactCollector runExporters (final ExporterAttributes attributes, final ExporterDefinition[] exporters, final IProgressMonitor monitor)
  +	private ArtifactCollector runExporters (final ExporterAttributes attributes, final ExporterFactory[] exporters, final IProgressMonitor monitor)
   	   throws CoreException
       {
   			
  @@ -260,13 +264,13 @@
                       
                       for (int i = 0; i < exporters.length; i++)
                       {
  -                       monitor.subTask(exporters[i].getDescription());
  +                       monitor.subTask(exporters[i].getExporterDefinition().getDescription());
                          
                          Properties exporterProperties = new Properties();
                          exporterProperties.putAll(props);
                          exporterProperties.putAll(exporters[i].getProperties());
                          
  -                       Exporter exporter = exporters[i].createExporterInstance();
  +                       Exporter exporter = exporters[i].getExporterDefinition().createExporterInstance();
                          
                          configureExporter (cfg, outputdir, templatePaths, exporterProperties, exporter);
                          
  @@ -366,4 +370,28 @@
   			throw new HibernateConsoleRuntimeException("Could not create or find " + className + " with one argument delegate constructor", e);
   		} 
       }
  +	
  +	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
  +		ExporterAttributes attributes = new ExporterAttributes(configuration);
  +		
  +		String configName = attributes.getConsoleConfigurationName();
  +		if(StringHelper.isEmpty( configName )) {
  +			abort("Console configuration name is empty in " + configuration.getName(), null, ICodeGenerationLaunchConstants.ERR_UNSPECIFIED_CONSOLE_CONFIGURATION);
  +		}
  +		
  +		if(KnownConfigurations.getInstance().find( configName )==null) {
  +			abort("Console configuration " + configName + " not found in " + configuration.getName(), null, ICodeGenerationLaunchConstants.ERR_CONSOLE_CONFIGURATION_NOTFOUND);
  +		}
  +		
  +		if(StringHelper.isEmpty(attributes.getOutputPath())) {
  +			abort("Output has to be specified in " + configuration.getName(), null, ICodeGenerationLaunchConstants.ERR_OUTPUT_PATH_NOTFOUND);
  +		}
  +		
  +		return super.preLaunchCheck( configuration, mode, monitor );
  +	}
  +	
  +	protected void abort(String message, Throwable exception, int code)
  +	throws CoreException {
  +		throw new CoreException(new Status(IStatus.ERROR, HibernateConsolePlugin.getDefault().ID, code, message, exception));
  +	}
   }
  
  
  
  1.1      date: 2006/08/10 07:01:51;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ICodeGenerationLaunchConstants.java
  
  Index: ICodeGenerationLaunchConstants.java
  ===================================================================
  package org.hibernate.eclipse.launch;
  
  public interface ICodeGenerationLaunchConstants {
  
  	int ERR_UNSPECIFIED_CONSOLE_CONFIGURATION = 1000;
  	int ERR_CONSOLE_CONFIGURATION_NOTFOUND = 1001;
  	int ERR_OUTPUT_PATH_NOTFOUND = 1002;
  
  }
  
  
  
  1.3       +186 -102  jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/AddPropertyDialog.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AddPropertyDialog.java
  ===================================================================
  RCS file: AddPropertyDialog.java
  diff -N AddPropertyDialog.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ AddPropertyDialog.java	10 Aug 2006 07:01:51 -0000	1.3
  @@ -0,0 +1,230 @@
  +package org.hibernate.eclipse.launch;
  +
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +import java.util.List;
  +import java.util.Map;
  +
  +import org.eclipse.jface.dialogs.IDialogConstants;
  +import org.eclipse.jface.dialogs.IMessageProvider;
  +import org.eclipse.jface.dialogs.TitleAreaDialog;
  +import org.eclipse.jface.viewers.ComboViewer;
  +import org.eclipse.jface.viewers.ILabelProvider;
  +import org.eclipse.jface.viewers.ILabelProviderListener;
  +import org.eclipse.jface.viewers.ISelectionChangedListener;
  +import org.eclipse.jface.viewers.IStructuredContentProvider;
  +import org.eclipse.jface.viewers.IStructuredSelection;
  +import org.eclipse.jface.viewers.SelectionChangedEvent;
  +import org.eclipse.jface.viewers.StructuredSelection;
  +import org.eclipse.jface.viewers.Viewer;
  +import org.eclipse.swt.SWT;
  +import org.eclipse.swt.events.ModifyEvent;
  +import org.eclipse.swt.events.ModifyListener;
  +import org.eclipse.swt.graphics.Image;
  +import org.eclipse.swt.layout.GridData;
  +import org.eclipse.swt.layout.GridLayout;
  +import org.eclipse.swt.widgets.Button;
  +import org.eclipse.swt.widgets.Combo;
  +import org.eclipse.swt.widgets.Composite;
  +import org.eclipse.swt.widgets.Control;
  +import org.eclipse.swt.widgets.Label;
  +import org.eclipse.swt.widgets.Shell;
  +import org.eclipse.swt.widgets.Text;
  +import org.hibernate.eclipse.console.model.impl.ExporterFactory;
  +import org.hibernate.eclipse.console.model.impl.ExporterProperty;
  +import org.hibernate.util.StringHelper;
  +
  +public class AddPropertyDialog extends TitleAreaDialog {
  +
  +	private final ExporterFactory ef;
  +	private ComboViewer propertyCombo;
  +	private Text value;
  +	private String propertyName;
  +	private String propertyValue;
  +
  +	protected AddPropertyDialog(Shell parentShell, ExporterFactory ef) {
  +		super( parentShell );
  +		this.ef = ef;
  +	}
  +	
  +	protected Control createDialogArea(Composite parent) {
  +		getShell().setText("Add exporter property"); 
  +		setTitle("Add property to " +  ef.getExporterDefinition().getDescription()); 
  +		Composite control = (Composite) super.createDialogArea( parent );
  +		
  +		Composite composite = new Composite(control,SWT.NONE);
  +		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
  +		GridLayout layout = new GridLayout(2,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( "Name:" );
  +		Combo combo = new Combo(composite, SWT.BORDER | SWT.LEAD | SWT.DROP_DOWN);
  +		combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
  +		combo.setFocus();
  +		combo.addModifyListener( modifyListener );
  +		propertyCombo = new ComboViewer(combo);
  +		
  +		label = new Label(composite, SWT.NONE);
  +		label.setText( "Value:" );
  +		
  +		value = new Text(composite, SWT.BORDER | SWT.LEAD );
  +		value.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL));
  +		value.addModifyListener( modifyListener );
  +		
  +		initDefaultNames(ef, propertyCombo);
  +		
  +		return control;
  +	}
  +
  +	private void initDefaultNames(ExporterFactory ef2, ComboViewer viewer) {
  +		viewer.setContentProvider( new IStructuredContentProvider() {
  +		
  +			ExporterFactory localEf;
  +			
  +			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
  +				localEf = (ExporterFactory) newInput;
  +			}
  +		
  +			public void dispose() {
  +				localEf = null;
  +			}
  +		
  +			public Object[] getElements(Object inputElement) {
  +				Iterator set = localEf.getDefaultExporterProperties().entrySet().iterator();
  +				List values = new ArrayList(4);
  +				while ( set.hasNext() ) {
  +					Map.Entry element = (Map.Entry) set.next();
  +					if(!localEf.hasLocalValueFor((String) element.getKey())) {
  +						ExporterProperty exporterProperty = localEf.getExporterProperty( (String) element.getKey() );
  +						if(exporterProperty!=null) {
  +							values.add(exporterProperty);
  +						}
  +					}			
  +				}
  +				return values.toArray( new ExporterProperty[values.size()] );
  +			}		
  +		});
  +		
  +		viewer.setLabelProvider( new ILabelProvider() {
  +		
  +			public void removeListener(ILabelProviderListener listener) {
  +				
  +			}
  +		
  +			public boolean isLabelProperty(Object element, String property) {
  +				return false;
  +			}
  +		
  +			public void dispose() {
  +				
  +			}
  +		
  +			public void addListener(ILabelProviderListener listener) {
  +				
  +			}
  +		
  +			public String getText(Object element) {
  +				ExporterProperty exporterProperty = ((ExporterProperty)element);
  +				return exporterProperty.getDescriptionForLabel(); 
  +			}
  +		
  +			public Image getImage(Object element) {
  +				return null;
  +			}
  +		
  +		} );
  +		
  +		viewer.addSelectionChangedListener( new ISelectionChangedListener() {
  +		
  +			public void selectionChanged(SelectionChangedEvent event) {
  +				if(value==null) return;
  +				IStructuredSelection iss = (IStructuredSelection) event.getSelection();
  +				if(!iss.isEmpty()) {
  +					value.setText( ((ExporterProperty)iss.getFirstElement()).getDefaultValue() );
  +				}
  +			}
  +		
  +		} );
  +		viewer.setInput( ef );
  +		if(viewer.getCombo().getItemCount()>0) {
  +			viewer.setSelection( new StructuredSelection(viewer.getElementAt( 0 )));
  +		}
  +	}
  +	
  +
  +	void updateStatus() {
  +		getEnteredValues();
  +		
  +		boolean ok = false;
  +		if(StringHelper.isEmpty( getPropertyName() )) {
  +			setMessage( "The property name must be chosen or entered",  IMessageProvider.ERROR);			
  +		} else if (getPropertyName().indexOf( ' ' )>=0 || getPropertyName().indexOf( '\t' )>=0) {
  +			setMessage( "The property name may not contain whitespaces", IMessageProvider.ERROR);
  +		} else if(StringHelper.isEmpty( getPropertyValue() )) {
  +			setMessage( "The property value must be non-empty",  IMessageProvider.ERROR);
  +		} else {
  +			if (ef.hasLocalValueFor( getPropertyName() )) {
  +				setMessage( "The property " + getPropertyName() + " is already set, pressing ok will overwrite the current value",  IMessageProvider.WARNING);
  +			} else {
  +				setMessage( null, IMessageProvider.ERROR );
  +			}
  +			ok = true;
  +		}
  +		
  +		Button button = getButton(IDialogConstants.OK_ID);
  +		if(button!=null) {
  +			button.setEnabled( ok );
  +		}
  +	}
  +	
  +	public String getPropertyValue() {
  +		return propertyValue;
  +	}
  +	
  +	public String getPropertyName() {
  +		return propertyName;		
  +	}
  +	
  +	void getEnteredValues() {
  +		if(propertyCombo==null) {
  +			propertyName = null;
  +		} else {
  +			IStructuredSelection selection = (IStructuredSelection) propertyCombo.getSelection();
  +			if(selection.isEmpty()) {
  +				propertyName = propertyCombo.getCombo().getText();
  +			} else {
  +				ExporterProperty p = (ExporterProperty) selection.getFirstElement();
  +				propertyName = p.getName();
  +			}
  +		}
  +		
  +		if(value!=null) {
  +			propertyValue = value.getText();	
  +		} else {
  +			propertyValue = null;
  +		}
  +	}
  +	
  +	protected void okPressed() {
  +		getEnteredValues();
  +		super.okPressed();		
  +	}
  +	
  +	public void create() {
  +		super.create();
  +		updateStatus();
  +	}
  +}
  
  
  
  1.1      date: 2006/08/10 07:01:51;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterFactoryPropertySource.java
  
  Index: ExporterFactoryPropertySource.java
  ===================================================================
  package org.hibernate.eclipse.launch;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.Map.Entry;
  
  import org.eclipse.ui.views.properties.IPropertyDescriptor;
  import org.eclipse.ui.views.properties.IPropertySource;
  import org.eclipse.ui.views.properties.PropertyDescriptor;
  import org.eclipse.ui.views.properties.TextPropertyDescriptor;
  import org.hibernate.eclipse.console.model.impl.ExporterFactory;
  import org.hibernate.eclipse.console.model.impl.ExporterProperty;
  
  public class ExporterFactoryPropertySource implements IPropertySource {
  
  	private final ExporterFactory factory;
  
  	public ExporterFactoryPropertySource(ExporterFactory factory) {
  		this.factory = factory;
  	}
  
  	public Object getEditableValue() {
  		// TODO Auto-generated method stub
  		return null;
  	}
  
  	public IPropertyDescriptor[] getPropertyDescriptors() {
  		List descriptors = new ArrayList();
  		
  		Map values = factory.getProperties();
  		
  		// get the values we explicitly have
  		Iterator iterator = values.keySet().iterator();
  		while ( iterator.hasNext() ) {
  			String key = (String) iterator.next();
  			
  			ExporterProperty element = factory.getExporterProperty(key);
  			
  			if(element!=null) {
  				descriptors.add(new TextPropertyDescriptor(element.getName(), element.getDescription()==null?element.getName():element.getDescription()));
  			} else {
  				descriptors.add(new TextPropertyDescriptor(key,key));
  			}
  		}
  				
  /* removed "default" show of properties since it gets confusing in the ui. 			
    Set set = factory.getDefaultExporterProperties().keySet();
  			for (Iterator iter = set.iterator(); iter.hasNext();) {
  				String key = (String) iter.next();
  				if(!values.containsKey( key )) {
  					ExporterProperty element = factory.getExporterProperty( key );
  
  					if(element!=null) {
  						descriptors.add(new TextPropertyDescriptor(element.getName(), element.getDescription()==null?element.getName():element.getDescription()));
  					}  
  				}			
  			}*/
  	
  		
  		return (IPropertyDescriptor[]) descriptors.toArray(new IPropertyDescriptor[0]);
  	}
  
  	public Object getPropertyValue(Object id) {
  		String propertyValue = factory.getPropertyValue( id.toString() );
  		if(propertyValue==null) {
  			return "";
  		} else {
  			return propertyValue;
  		}		
  	}
  
  	public boolean isPropertySet(Object id) {
  		return false;
  	}
  
  	public void resetPropertyValue(Object id) {
  	
  	}
  
  	public void setPropertyValue(Object id, Object value) {
  		factory.setProperty( id.toString(), value.toString() );
  	}
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list