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

Max Rydahl Andersen mandersen at jboss.com
Thu Sep 21 18:58:36 EDT 2006


  User: mandersen
  Date: 06/09/21 18:58:36

  Modified:    hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console     
                        QueryEditor.java HibernateConsolePlugin.java
  Added:       hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console     
                        AbstractQueryEditor.java QueryEditorStorage.java
                        QueryEditorInput.java
  Log:
  HBX-763 open hql and criteria editor should always be active
  HBX-762 Show run button and console combo inside the query/criteria editor
  
  Revision  Changes    Path
  1.3       +2 -0      jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/QueryEditor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: QueryEditor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/QueryEditor.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- QueryEditor.java	7 Jul 2006 13:51:11 -0000	1.2
  +++ QueryEditor.java	21 Sep 2006 22:58:36 -0000	1.3
  @@ -36,4 +36,6 @@
   
   	void executeQuery(ConsoleConfiguration cfg);
   
  +	void setConsoleConfigurationName(String text);
  +
   }
  
  
  
  1.29      +13 -7     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HibernateConsolePlugin.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsolePlugin.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- HibernateConsolePlugin.java	25 Aug 2006 11:39:38 -0000	1.28
  +++ HibernateConsolePlugin.java	21 Sep 2006 22:58:36 -0000	1.29
  @@ -248,6 +248,11 @@
   		 	      "Hibernate Console", message, warning);		
   	}
   	
  +	public void showError(Shell shell, String message, IStatus s) {
  +		log(s);
  +	 	   ErrorDialog.openError(shell, 
  +	 	      "Hibernate Console", message, s);				
  +	}
   	
   	public void openCriteriaEditor(String consoleName, String criteria) {
   		 try {
  @@ -256,7 +261,7 @@
   		        IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
   		        
   		        
  -		        CriteriaEditorStorage storage = new CriteriaEditorStorage(consoleName, "Critieria: " + consoleName, criteria==null?"":criteria);		        
  +		        CriteriaEditorStorage storage = new CriteriaEditorStorage(consoleName, criteria==null?"":criteria);		        
   		        
   		        final CriteriaEditorInput editorInput = new CriteriaEditorInput(storage);
   		        page.openEditor(editorInput, "org.hibernate.eclipse.criteriaeditor.CriteriaEditor", true);
  @@ -273,7 +278,7 @@
   		        IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
   		        
   		        
  -		        HQLEditorStorage storage = new HQLEditorStorage(consoleName, "HQL: " + consoleName, hql==null?"":hql);		        
  +		        HQLEditorStorage storage = new HQLEditorStorage(consoleName, hql==null?"":hql);		        
   		        
   		        final HQLEditorInput editorInput = new HQLEditorInput(storage);
   		            page.openEditor(editorInput, "org.hibernate.eclipse.hqleditor.HQLEditor", true);
  @@ -282,7 +287,7 @@
   		    }
   	}
   
  -	public ConsoleConfiguration getLastUsedConfiguration() {
  +	/*public ConsoleConfiguration getLastUsedConfiguration() {
   		String lastUsedName = getDefault().getPreferenceStore().getString(HibernateConsolePlugin.LAST_USED_CONFIGURATION_PREFERENCE);
   		
   		ConsoleConfiguration lastUsed = (lastUsedName == null || lastUsedName.trim().length()==0) 
  @@ -294,9 +299,9 @@
   	    }
   	    
   		return lastUsed;
  -	}
  +	}*/
   	
  -	public void setLastUsedConfiguration(ConsoleConfiguration lastUsed) {
  +	/*public void setLastUsedConfiguration(ConsoleConfiguration lastUsed) {
   		String name;
   		if(lastUsed==null) {
   			name = "";
  @@ -306,7 +311,7 @@
   		
   		HibernateConsolePlugin.getDefault().getPreferenceStore().setValue(
   				LAST_USED_CONFIGURATION_PREFERENCE, name );
  -	}
  +	}*/
   	
   	/**
   	 * Convenience method for showing an error dialog 
  @@ -449,4 +454,5 @@
   	}
   
   	
  +	
   }
  
  
  
  1.1      date: 2006/09/21 22:58:36;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/AbstractQueryEditor.java
  
  Index: AbstractQueryEditor.java
  ===================================================================
  package org.hibernate.eclipse.console;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.core.runtime.IProgressMonitor;
  import org.eclipse.jface.action.ActionContributionItem;
  import org.eclipse.jface.action.ControlContribution;
  import org.eclipse.jface.action.ToolBarManager;
  import org.eclipse.jface.dialogs.MessageDialog;
  import org.eclipse.jface.text.IDocument;
  import org.eclipse.swt.SWT;
  import org.eclipse.swt.events.SelectionAdapter;
  import org.eclipse.swt.events.SelectionEvent;
  import org.eclipse.swt.layout.GridData;
  import org.eclipse.swt.layout.RowData;
  import org.eclipse.swt.layout.RowLayout;
  import org.eclipse.swt.widgets.Combo;
  import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Control;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.ToolBar;
  import org.eclipse.ui.IEditorInput;
  import org.eclipse.ui.IShowEditorInput;
  import org.eclipse.ui.IWorkbenchPart;
  import org.eclipse.ui.editors.text.TextEditor;
  import org.eclipse.ui.texteditor.IDocumentProvider;
  import org.hibernate.SessionFactory;
  import org.hibernate.console.ConsoleConfiguration;
  import org.hibernate.console.KnownConfigurations;
  import org.hibernate.console.KnownConfigurationsListener;
  import org.hibernate.console.QueryInputModel;
  import org.hibernate.eclipse.console.actions.ExecuteQueryAction;
  
  public abstract class AbstractQueryEditor extends TextEditor implements
  		QueryEditor, IShowEditorInput {
  
  	private ToolBarManager tbm;
  	final private QueryInputModel queryInputModel;
  	
  	public AbstractQueryEditor() {
  		queryInputModel = new QueryInputModel();
  	}
  	
  	final public boolean askUserForConfiguration(String name) {
  		return MessageDialog.openQuestion( HibernateConsolePlugin.getDefault()
  				.getWorkbench().getActiveWorkbenchWindow().getShell(),
  				"Open Session factory",
  				"Do you want to open the session factory for " + name + " ?" );
  	}
  
  	final public ConsoleConfiguration getConsoleConfiguration() {
  		return KnownConfigurations.getInstance().find(
  				getConsoleConfigurationName() );
  	}
  
  	final public String getConsoleConfigurationName() {
  		QueryEditorInput hei = (QueryEditorInput) getEditorInput();
  		return hei.getConsoleConfigurationName();
  	}
  
  	final public void setConsoleConfigurationName(String name) {
  		QueryEditorInput hei = (QueryEditorInput) getEditorInput();
  		hei.setConsoleConfigurationName( name );
  		hei.resetName();
  		showEditorInput( hei );
  	}
  
  	public void showEditorInput(IEditorInput editorInput) {
  
  		try {
  			doSetInput( editorInput );
  		}
  		catch (CoreException e) {
  			HibernateConsolePlugin.getDefault().logErrorMessage(
  					"Could not show query editor input", e );
  		}
  	}
  
  	final public void doSave(IProgressMonitor progressMonitor) {
  		// super.doSave(progressMonitor);
  		QueryEditorInput hei = (QueryEditorInput) getEditorInput();
  		hei.setQuery( getQueryString() );
  		performSave( false, progressMonitor );
  	}
  
  	final public String getQueryString() {
  		IEditorInput editorInput = getEditorInput();
  		IDocumentProvider docProvider = getDocumentProvider();
  		IDocument doc = docProvider.getDocument( editorInput );
  		return doc.get();
  	}
  
  	protected final class ConfigurationCombo extends ControlContribution {
  		private KnownConfigurationsListener listener;
  
  		private SelectionAdapter selectionAdapter;
  
  		private Combo consoleSelection;
  
  		private QueryEditor editor;
  
  		protected ConfigurationCombo(String id, QueryEditor qe) {
  			super( id );
  			this.editor = qe;
  		}
  
  		protected Control createControl(Composite parent) {
  			Composite panel = new Composite( parent, SWT.NONE );
  			panel.setLayout( new RowLayout() );
  			consoleSelection = new Combo( panel, SWT.DROP_DOWN | SWT.READ_ONLY );
  			consoleSelection.setLayoutData( new RowData(100, SWT.DEFAULT) );
  			
  			populateCombo( consoleSelection );
  
  			selectionAdapter = new SelectionAdapter() {
  
  				public void widgetSelected(SelectionEvent e) {
  					editor.setConsoleConfigurationName( consoleSelection
  							.getText() );
  				}
  
  			};
  
  			consoleSelection.addSelectionListener( selectionAdapter );
  
  			listener = new KnownConfigurationsListener() {
  
  				public void sessionFactoryClosing(
  						ConsoleConfiguration configuration,
  						SessionFactory closingFactory) {
  				}
  
  				public void sessionFactoryBuilt(ConsoleConfiguration ccfg,
  						SessionFactory builtFactory) {
  				}
  
  				public void configurationRemoved(ConsoleConfiguration root) {
  					populateCombo( consoleSelection );
  				}
  
  				public void configurationAdded(ConsoleConfiguration root) {
  					populateCombo( consoleSelection );
  				}
  			};
  			KnownConfigurations.getInstance().addConsoleConfigurationListener(
  					listener );
  
  			return panel;
  		}
  
  		private void populateCombo(final Combo config) {
  			ConsoleConfiguration[] configurations = KnownConfigurations
  					.getInstance().getConfigurations();
  			final String[] names = new String[configurations.length];
  			for (int i = 0; i < configurations.length; i++) {
  				names[i] = configurations[i].getName();
  			}
  
  			final String name = getConsoleConfigurationName()==null?"":getConsoleConfigurationName();
  			
  			config.getDisplay().syncExec( new Runnable() {
  			
  				public void run() {
  					config.setItems( names );			
  					config.setText( name );
  				}
  			
  			} );
  			
  		}
  
  		public void dispose() {
  			if ( listener != null ) {
  				KnownConfigurations.getInstance().removeConfigurationListener(
  						listener );
  			}
  			if ( selectionAdapter != null ) {
  				if ( !consoleSelection.isDisposed() ) {
  					consoleSelection.removeSelectionListener( selectionAdapter );
  				}
  			}
  		}
  
  	}
  
  	/**
  	 * Dispose of resources held by this editor.
  	 * 
  	 * @see IWorkbenchPart#dispose()
  	 */
  	final public void dispose() {
  		super.dispose();
  		if ( tbm != null )
  			tbm.dispose();
  	}
  
  	final protected void createToolbar(Composite parent) {
  		ToolBar bar = new ToolBar( parent, SWT.HORIZONTAL );
  		bar.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
  
  		tbm = new ToolBarManager( bar );
  		ActionContributionItem item = new ActionContributionItem(
  				new ExecuteQueryAction( this ) );
  
  		tbm.add( item );
  
  		ControlContribution cc = new ConfigurationCombo( "hql-target", this );
  		tbm.add( cc );
  
  		tbm.update( true );
  
  	}
  	
  	protected void initializeKeyBindingScopes() {
  	       setKeyBindingScopes(new String[] { "org.hibernate.eclipse.console.hql" });  //$NON-NLS-1$
  	   }
  
  	public QueryInputModel getQueryInputModel() {
  		return queryInputModel;
  	}
  }
  
  
  
  1.1      date: 2006/09/21 22:58:36;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/QueryEditorStorage.java
  
  Index: QueryEditorStorage.java
  ===================================================================
  package org.hibernate.eclipse.console;
  
  import java.io.BufferedReader;
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.Reader;
  
  import org.eclipse.core.resources.IStorage;
  import org.eclipse.core.runtime.IPath;
  
  public class QueryEditorStorage implements IStorage {
  
  	private String contents;
      private String nameLabel;
  	private String configurationName;
  
      public QueryEditorStorage( String source ) {
          this( "", source, source );
      }
  
      public QueryEditorStorage( String configurationName, String name, String source ) {
          super();
          setName( name );
          setQuery( source );
          setConfigurationName(configurationName);
      }
  
  	public void setQuery(String source) {
  		if(source==null) { return; }
  		setContents(source);
  	}
  
      public Object getAdapter( Class key ) {
          return null;
      }
  
      public InputStream getContents() {
      	return new ByteArrayInputStream( contents.getBytes() );
      }
  
      /**
       * @return contents as a string
       */
      public String getContentsString() {
          String contentsString = ""; 
          
          InputStream contentsStream = getContents();
          
          // The following code was adapted from StorageDocumentProvider.setDocumentContent method.
          Reader in = null;
          try {
              in = new BufferedReader( new InputStreamReader( contentsStream ));
              StringBuffer buffer = new StringBuffer();
              char[] readBuffer = new char[2048];
              int n = in.read( readBuffer );
              while (n > 0) {
                  buffer.append( readBuffer, 0, n );
                  n = in.read( readBuffer );
              }
              contentsString = buffer.toString();
          } catch (IOException x) {
              // ignore and save empty content
          } finally {
              if (in != null) {
                  try {
                      in.close();
                  } catch (IOException x) {
                      // ignore, too late to do anything here
                  }
              }
          }
  
          return contentsString;
      }
      
      public IPath getFullPath() {
          return null;
      }
  
      public String getName() {
          return nameLabel;
      }
  
      public boolean isReadOnly() {
          return false;
      }
  
  
      public void setName( String name ) {
          nameLabel = name;
      }
  
  	public String getConfigurationName() {
  		return configurationName;
  	}
  
  	public void setConfigurationName(String configurationName) {
  		this.configurationName = configurationName;		
  	}
  
  	public void setContents(String query) {
  		this.contents = query;
  	}
  
  }
  
  
  
  1.1      date: 2006/09/21 22:58:36;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/QueryEditorInput.java
  
  Index: QueryEditorInput.java
  ===================================================================
  package org.hibernate.eclipse.console;
  
  import org.eclipse.core.resources.IStorage;
  import org.eclipse.jface.resource.ImageDescriptor;
  import org.eclipse.ui.IPersistableElement;
  import org.eclipse.ui.IStorageEditorInput;
  
  public abstract class QueryEditorInput  implements IStorageEditorInput, IPersistableElement {
  
      /** The name of ths editor input. */
      private String name;
      /** The storage object used by this editor input. */
      private IStorage storage;
  
      /**
       * Constructs an instance of this class with the given <code>IStorage</code>
       * object as the editor input source.
       * 
       * @param storage the storage object for this editor input
       */
      public QueryEditorInput( IStorage storage ) {
  		if (storage == null) {
  			throw new IllegalArgumentException();
          }
          setStorage( storage );
          setName( storage.getName() );
      }    
  
      /**
       * Gets whether the editor input exists.
       * 
       * @see org.eclipse.ui.IEditorInput#exists()
       */
      public boolean exists() {
          if (storage != null)
              return true;
          
          return false;
      }
  
      public Object getAdapter( Class adapter ) {
          return null;
      }
  
      public ImageDescriptor getImageDescriptor() {
          return null;
      }
  
      public String getName() {
          return name;
      }
  
      public IStorage getStorage() {
          return storage;
      }
  
      public String getToolTipText() {        
          return getName();        
      }
  
    
      public void setName( String name ) {
          this.name = name;
      }
  
      public void setStorage( IStorage storage ) {
          this.storage = storage;
      }
  
  	public IPersistableElement getPersistable() {
  		return this;
  	}
  
  	
  	public boolean equals(Object obj) { // used to identify if HQL editor is the same
  		/*if(obj instanceof HQLEditorInput) {
  			
  			return ((HQLEditorInput)obj).getConsoleConfigurationName().equals(getConsoleConfigurationName());
  		}*/
  		return super.equals(obj);
  	}
  	
  	public int hashCode() {
  		return name==null?0:name.hashCode();
  	}
  
  
  	public void setQuery(String query) {
  		((QueryEditorStorage)getStorage()).setContents(query);		
  	}
  
  	public String getConsoleConfigurationName() {
  		return ((QueryEditorStorage)getStorage()).getConfigurationName();
  	}
  
  	public void setConsoleConfigurationName(String name2) {
  		((QueryEditorStorage)getStorage()).setConfigurationName(name2);		
  	}
  
  	abstract public void resetName();
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list