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

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


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

  Modified:    hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor    
                        HQLEditorStorage.java
                        HQLEditorActionContributor.java HQLEditor.java
                        HQLEditorInput.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       +6 -94     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorStorage.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HQLEditorStorage.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorStorage.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- HQLEditorStorage.java	7 Jul 2006 13:51:08 -0000	1.2
  +++ HQLEditorStorage.java	21 Sep 2006 22:58:36 -0000	1.3
  @@ -21,111 +21,23 @@
    */
   package org.hibernate.eclipse.hqleditor;
   
  -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;
  +import org.hibernate.eclipse.console.QueryEditorStorage;
   
   /**
    * Storage for HQL editors without a file
    */
  -public class HQLEditorStorage implements IStorage {
  -    
  -	private String contents;
  -    private String nameLabel;
  -	private String configurationName;
  +public class HQLEditorStorage extends QueryEditorStorage {
   
       public HQLEditorStorage( String source ) {
  -        this( "", source, source );
  +        super(source);
       }
   
       public HQLEditorStorage( 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;		
  +        super(configurationName,name, source);        
   	}
   
  -	public void setContents(String query) {
  -		this.contents = query;
  +    public HQLEditorStorage(String consoleName, String string) {
  +		super(consoleName, "HQL: " + (consoleName==null?"<None>":consoleName), string);
   	}
   
   }
  \ No newline at end of file
  
  
  
  1.5       +12 -4     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorActionContributor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HQLEditorActionContributor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorActionContributor.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- HQLEditorActionContributor.java	7 Jul 2006 13:51:08 -0000	1.4
  +++ HQLEditorActionContributor.java	21 Sep 2006 22:58:36 -0000	1.5
  @@ -24,6 +24,7 @@
   import java.util.ResourceBundle;
   
   import org.eclipse.jface.action.IMenuManager;
  +import org.eclipse.jface.action.IToolBarManager;
   import org.eclipse.jface.action.Separator;
   import org.eclipse.ui.IActionBars;
   import org.eclipse.ui.IEditorPart;
  @@ -35,7 +36,7 @@
   import org.eclipse.ui.texteditor.RetargetTextEditorAction;
   import org.hibernate.eclipse.console.Messages;
   import org.hibernate.eclipse.console.QueryEditor;
  -import org.hibernate.eclipse.console.actions.ExecuteHQLAction;
  +import org.hibernate.eclipse.console.actions.ExecuteQueryAction;
   
   
   
  @@ -48,7 +49,7 @@
       protected RetargetTextEditorAction contentAssistTipAction;
       protected RetargetTextEditorAction contentFormatAction;
       
  -    private ExecuteHQLAction executeHQLAction;
  +    private ExecuteQueryAction executeHQLAction;
   	
   
       /**
  @@ -61,7 +62,7 @@
           contentAssistProposalAction = new RetargetTextEditorAction( bundle, "ContentAssistProposal." ); // $NON-NLS-1$
           contentAssistTipAction =  new RetargetTextEditorAction( bundle, "ContentAssistTip." ); // $NON-NLS-1$
           contentFormatAction = new RetargetTextEditorAction( bundle, "ContentFormat." ); // $NON-NLS-1$
  -        executeHQLAction = new ExecuteHQLAction();
  +        executeHQLAction = new ExecuteQueryAction();
           
       }
   
  @@ -113,11 +114,18 @@
           }        
       }
       
  +    public void contributeToToolBar(IToolBarManager toolBarManager) {
  +    	
  +    	super.contributeToToolBar( toolBarManager );
  +    	
  +    	
  +    }
  +    
       public void init(IActionBars bars, IWorkbenchPage page) {
       	super.init( bars, page );
       	
   //    	bars.setGlobalActionHandler("org.hibernate.eclipse.console.actions.ClearHQLEditorAction", fClearHQLEditorAction);
  -    	bars.setGlobalActionHandler("org.hibernate.eclipse.console.actions.ExecuteHQLAction", executeHQLAction);
  +    	bars.setGlobalActionHandler("org.hibernate.eclipse.console.actions.ExecuteQueryAction", executeHQLAction);
       	bars.updateActionBars();
       }
       
  
  
  
  1.11      +40 -122   jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HQLEditor.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- HQLEditor.java	7 Jul 2006 13:51:08 -0000	1.10
  +++ HQLEditor.java	21 Sep 2006 22:58:36 -0000	1.11
  @@ -21,14 +21,17 @@
    */
   package org.hibernate.eclipse.hqleditor;
   
  +
   import java.util.ResourceBundle;
   
   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.IAction;
   import org.eclipse.jface.action.IMenuManager;
   import org.eclipse.jface.action.Separator;
  -import org.eclipse.jface.dialogs.MessageDialog;
  +import org.eclipse.jface.action.ToolBarManager;
   import org.eclipse.jface.text.IDocument;
   import org.eclipse.jface.text.ITextViewer;
   import org.eclipse.jface.text.source.ISourceViewer;
  @@ -37,23 +40,36 @@
   import org.eclipse.jface.text.source.projection.ProjectionViewer;
   import org.eclipse.jface.util.IPropertyChangeListener;
   import org.eclipse.jface.util.PropertyChangeEvent;
  +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.GridLayout;
  +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.ToolBar;
  +import org.eclipse.swt.widgets.ToolItem;
   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.DefaultRangeIndicator;
   import org.eclipse.ui.texteditor.IDocumentProvider;
   import org.eclipse.ui.texteditor.ITextEditor;
   import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
   import org.eclipse.ui.texteditor.TextOperationAction;
   import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
  +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.AbstractQueryEditor;
   import org.hibernate.eclipse.console.HibernateConsolePlugin;
   import org.hibernate.eclipse.console.Messages;
   import org.hibernate.eclipse.console.QueryEditor;
  +import org.hibernate.eclipse.console.QueryEditorInput;
  +import org.hibernate.eclipse.console.actions.ExecuteQueryAction;
   import org.hibernate.eclipse.console.views.IQueryParametersPage;
   import org.hibernate.eclipse.console.views.QueryParametersPage;
   
  @@ -61,7 +77,9 @@
   /**
    * HQL Editor
    */
  -public class HQLEditor extends TextEditor implements IPropertyChangeListener, IShowEditorInput, QueryEditor {
  +public class HQLEditor extends AbstractQueryEditor {
  +	
  +
   	public static final String PLUGIN_NAME = HibernateConsolePlugin.ID;
   	public static final String HELP_CONTEXT_ID = PLUGIN_NAME + ".hqleditorhelp"; //$NON-NLS-1$
   	
  @@ -71,14 +89,14 @@
       private HQLEditorDocumentSetupParticipant docSetupParticipant;
       /** The projection (code folding) support object. */
       private ProjectionSupport fProjectionSupport;
  -	final private QueryInputModel queryInputModel;
  +	
  +	
       
       /**
        * Constructs an instance of this class. This is the default constructor.
        */
       public HQLEditor() {
           super();
  -        queryInputModel = new QueryInputModel();
       }
   
       /**
  @@ -110,7 +128,7 @@
           setAction( "HQLEditor.disconnectAction", a ); //$NON-NLS-1$
           */
           
  -//        a = new ExecuteHQLAction( this ); //$NON-NLS-1$
  +//        a = new ExecuteQueryAction( this ); //$NON-NLS-1$
   //        setAction( "HQLEditor.runAction", a ); //$NON-NLS-1$
           
           /*a = new HQLSetStatementTerminatorAction( bundle, "HQLEditor.setStatementTerminatorAction." ); //$NON-NLS-1$
  @@ -128,7 +146,16 @@
        * @see org.eclipse.ui.texteditor.AbstractTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
        */
       public void createPartControl( Composite parent ) {
  +    	parent.setLayout( new GridLayout(1,false) );
  +    	    	
  +    	createToolbar(parent);
  +    	
           super.createPartControl( parent );
  +    	
  +    	// move to base class?
  +    	Control control = parent.getChildren()[1];
  +    	control.setLayoutData( new GridData( GridData.FILL_BOTH ) );
  +    	
           setProjectionSupport( createProjectionSupport() );
           
           /* Now that we have enabled source folding, make sure everything is
  @@ -183,27 +210,6 @@
       }
   
       /**
  -     * Dispose of resources held by this editor.
  -     * 
  -     * @see IWorkbenchPart#dispose()
  -     */
  -    public void dispose() {
  -        super.dispose();
  -    }
  -
  -    /**
  -     * Abandons all modifications applied to this text editor's input element's
  -     * textual presentation since the last save operation.
  -     * 
  -     * @see ITextEditor#doRevertToSaved()
  -     */
  -    public void doRevertToSaved() {
  -        super.doRevertToSaved();
  -        //updateOutlinePage();
  -    }
  -
  - 
  -    /**
        * Sets the input of the outline page after this class has set input.
        * 
        * @param input the new input for the editor
  @@ -225,41 +231,6 @@
               }
           }
   
  -        /* Determine if our input object is an instance of IHQLEditorInput.  If so,
  -         * get all the information that it contains.
  -         */
  -        /*ConnectionInfo connInfo = null;
  -        Database db = null;
  -        String defaultSchemaName = null;
  -        if (input instanceof IHQLEditorInput) {
  -            IHQLEditorInput hqlInput = (IHQLEditorInput) input;
  -            connInfo = hqlInput.getConnectionInfo();
  -            db = sqlInput.getDatabase();
  -            defaultSchemaName = sqlInput.getDefaultSchemaName();
  -        }*/
  -        
  -        /* If we didn't get a database but we did get a connection, try to get
  -         * the database from the connection.
  -         */
  -        /*if (connInfo != null && db == null) {
  -            db = connInfo.getSharedDatabase();
  -        }*/
  -        
  -        /* Save away the connection and the database information. */
  -        //setConnectionInfo( connInfo );
  -        //setDatabase( db );
  -        //setDefaultSchemaName( defaultSchemaName );
  -
  -        /* Show the connection status in the status area at the bottom of the
  -         * workbench window.
  -         */
  -        //refreshConnectionStatus();
  -        
  -        /* Pass the input along to the outline page. */
  -        //HQLEditorContentOutlinePage outlinePage = getOutlinePage();
  -        //if (outlinePage != null) {
  -        //    outlinePage.setInput( input );
  -        //}
       }
   
       /**
  @@ -392,20 +363,6 @@
           setRangeIndicator( new DefaultRangeIndicator() );
       }
       
  -    /**
  -     * Handles notifications to the object that a property has changed.
  -     * 
  -     * @param event the property change event object describing which property
  -     *            changed and how
  -     */
  -    public void propertyChange( PropertyChangeEvent event ) {
  -        /*if (event.getProperty().equals( HQLConnectAction.CONNECTION )) {
  -            ConnectionInfo connInfo = (ConnectionInfo) event.getNewValue();
  -            setConnectionInfo( connInfo );
  -            refreshConnectionStatus();
  -        }*/
  -    }
  -
     
       /**
        * Sets the document setup participant object associated with this editor to
  @@ -415,7 +372,7 @@
        * @return the current document setup participant
        */
       public void setDocumentSetupParticipant( HQLEditorDocumentSetupParticipant docSetupParticipant ) {
  -        docSetupParticipant = docSetupParticipant;
  +        this.docSetupParticipant = docSetupParticipant;
       }
   
       /**
  @@ -428,55 +385,16 @@
           fProjectionSupport = projSupport;
       }
   
  -	public void showEditorInput(IEditorInput editorInput) {
  -		
  -			try {
  -				doSetInput(editorInput);
  -			}
  -			catch (CoreException e) {
  -				HibernateConsolePlugin.getDefault().logErrorMessage( "Could not show HQL editor input", e );
  -			}
  -	}
  -
  -	public String getQueryString() {		
  -        IEditorInput editorInput = getEditorInput();
  -        IDocumentProvider docProvider = getDocumentProvider();
  -        IDocument doc = docProvider.getDocument( editorInput );
  -        return doc.get();
  -	}
  -
  -   public void doSave(IProgressMonitor progressMonitor) { 
  -	   //super.doSave(progressMonitor);
  -	   HQLEditorInput hei = (HQLEditorInput)getEditorInput();
  -	   hei.setQuery(getQueryString());
  -	   performSave(false, progressMonitor);
  -   }
  -   
  - 
  -
  -   public ConsoleConfiguration getConsoleConfiguration() {
  -	   HQLEditorInput hei = (HQLEditorInput)getEditorInput();
  -	   return KnownConfigurations.getInstance().find(hei.getConsoleConfigurationName());
  -   }
  -
  -   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 + " ?");        
  -   }
   
      public ITextViewer getTextViewer() {
   	   return getSourceViewer();
      }
      
  -   protected void initializeKeyBindingScopes() {
  -       setKeyBindingScopes(new String[] { "org.hibernate.eclipse.console.hql" });  //$NON-NLS-1$
  -   }
   
  -   public QueryInputModel getQueryInputModel() {
  -	   return queryInputModel;
  -   }
   
      public void executeQuery(ConsoleConfiguration cfg) {
   	   cfg.executeHQLQuery(getQueryString(), getQueryInputModel().getQueryParametersForQuery() );	
      }
   
  +  
   } 
  
  
  
  1.4       +8 -86     jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorInput.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HQLEditorInput.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLEditorInput.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- HQLEditorInput.java	7 Jul 2006 13:51:08 -0000	1.3
  +++ HQLEditorInput.java	21 Sep 2006 22:58:36 -0000	1.4
  @@ -22,93 +22,20 @@
   package org.hibernate.eclipse.hqleditor;
   
   import org.eclipse.core.resources.IStorage;
  -import org.eclipse.jface.resource.ImageDescriptor;
   import org.eclipse.ui.IMemento;
  -import org.eclipse.ui.IPersistableElement;
  -import org.eclipse.ui.IStorageEditorInput;
  +import org.hibernate.eclipse.console.QueryEditorInput;
   
   /**
    * input for hql editor on non file based storage.
    */
  -public class HQLEditorInput implements IStorageEditorInput, IPersistableElement {
  -
  -    /** The name of ths editor input. */
  -    private String name;
  -    /** The storage object used by this editor input. */
  -    private IStorage storage;
  +public class HQLEditorInput extends QueryEditorInput {
   
       public HQLEditorInput( String storageSource ) {
  -        this( new HQLEditorStorage( storageSource ) );
  +        super( new HQLEditorStorage( storageSource ) );
       }
   
  -    /**
  -     * 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 HQLEditorInput( 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 = (HQLEditorStorage) storage;
  -    }
  -
  -	public IPersistableElement getPersistable() {
  -		return this;
  -	}
  -
  -	public boolean equals(Object obj) {
  -		if(obj instanceof HQLEditorInput) {
  -			return ((HQLEditorInput)obj).getName().equals(name);
  -		}
  -		return super.equals(obj);
  -	}
  -	
  -	public int hashCode() {
  -		return name.hashCode();
  +    	super(storage);    	
   	}
   
       public String getFactoryId() {
  @@ -119,12 +46,7 @@
           HQLEditorInputFactory.saveState( memento, this );
       }
   
  -	public void setQuery(String query) {
  -		((HQLEditorStorage)storage).setContents(query);		
  -	}
  -
  -	public String getConsoleConfigurationName() {
  -		return ((HQLEditorStorage)storage).getConfigurationName();
  +    public void resetName() {
  +    	setName( "HQL: " + getConsoleConfigurationName()==null?"<None>":getConsoleConfigurationName() );    	
   	}
  -
   } 
  
  
  



More information about the jboss-cvs-commits mailing list