[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor ...
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/criteriaeditor
CriteriaEditorActionContributor.java
CriteriaEditor.java CriteriaEditorInput.java
CriteriaEditorStorage.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.5 +4 -5 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorActionContributor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CriteriaEditorActionContributor.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorActionContributor.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CriteriaEditorActionContributor.java 7 Jul 2006 13:51:10 -0000 1.4
+++ CriteriaEditorActionContributor.java 21 Sep 2006 22:58:37 -0000 1.5
@@ -27,9 +27,8 @@
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
import org.eclipse.ui.part.EditorActionBarContributor;
-import org.eclipse.ui.texteditor.ITextEditor;
import org.hibernate.eclipse.console.QueryEditor;
-import org.hibernate.eclipse.console.actions.ExecuteHQLAction;
+import org.hibernate.eclipse.console.actions.ExecuteQueryAction;
/**
@@ -37,11 +36,11 @@
*/
public class CriteriaEditorActionContributor extends TextEditorActionContributor {
- private ExecuteHQLAction executeHQLAction;
+ private ExecuteQueryAction executeHQLAction;
public CriteriaEditorActionContributor() {
super();
- executeHQLAction = new ExecuteHQLAction();
+ executeHQLAction = new ExecuteQueryAction();
}
/**
@@ -72,7 +71,7 @@
public void init(IActionBars bars, IWorkbenchPage page) {
super.init( bars, page );
- bars.setGlobalActionHandler("org.hibernate.eclipse.console.actions.ExecuteHQLAction", executeHQLAction);
+ bars.setGlobalActionHandler("org.hibernate.eclipse.console.actions.ExecuteQueryAction", executeHQLAction);
bars.updateActionBars();
}
1.6 +20 -42 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CriteriaEditor.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditor.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CriteriaEditor.java 7 Jul 2006 13:51:10 -0000 1.5
+++ CriteriaEditor.java 21 Sep 2006 22:58:37 -0000 1.6
@@ -28,38 +28,35 @@
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.eval.IEvaluationContext;
import org.eclipse.jdt.ui.PreferenceConstants;
import org.eclipse.jdt.ui.text.java.CompletionProposalCollector;
import org.eclipse.jface.action.Action;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IShowEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.console.KnownConfigurations;
-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.mapping.PersistentClass;
-public class CriteriaEditor extends AbstractDecoratedTextEditor implements QueryEditor, IShowEditorInput {
+public class CriteriaEditor extends AbstractQueryEditor {
- final private QueryInputModel queryInputModel;
private CriteriaEditorDocumentSetupParticipant docSetupParticipant;
public CriteriaEditor() {
@@ -78,7 +75,6 @@
setEditorContextMenuId("#CriteraEditorContext"); //$NON-NLS-1$
setRulerContextMenuId("#CriteraRulerContext"); //$NON-NLS-1$
- queryInputModel = new QueryInputModel();
}
protected void createActions() {
@@ -93,29 +89,6 @@
return ResourceBundle.getBundle( Messages.BUNDLE_NAME );
}
- 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 ConsoleConfiguration getConsoleConfiguration() {
- CriteriaEditorInput hei = (CriteriaEditorInput)getEditorInput();
- return KnownConfigurations.getInstance().find(hei.getConsoleConfigurationName());
- }
-
- public QueryInputModel getQueryInputModel() {
- return queryInputModel;
- }
-
- public String getQueryString() {
- IEditorInput editorInput = getEditorInput();
- IDocumentProvider docProvider = getDocumentProvider();
- IDocument doc = docProvider.getDocument( editorInput );
- return doc.get();
- }
-
- protected void initializeKeyBindingScopes() {
- setKeyBindingScopes(new String[] { "org.hibernate.eclipse.console.hql" }); //$NON-NLS-1$
- }
protected void doSetInput(IEditorInput input) throws CoreException {
@@ -196,24 +169,29 @@
}
- public void doSave(IProgressMonitor progressMonitor) {
- //super.doSave(progressMonitor);
- CriteriaEditorInput hei = (CriteriaEditorInput)getEditorInput();
- hei.setQuery(getQueryString());
- performSave(false, progressMonitor);
- }
-
public void showEditorInput(IEditorInput editorInput) {
CriteriaEditorInput hei = (CriteriaEditorInput)getEditorInput();
-
+ super.showEditorInput( editorInput );
IStorage storage = ((CriteriaEditorInput)editorInput).getStorage();
if (storage instanceof CriteriaEditorStorage) {
CriteriaEditorStorage sqlEditorStorage = (CriteriaEditorStorage) storage;
- getDocumentProvider().getDocument( hei ).set( sqlEditorStorage.getContentsString() );
+ IDocument document = getDocumentProvider().getDocument( hei );
+ document.set( sqlEditorStorage.getContentsString() );
}
}
+ public void createPartControl(Composite parent) {
+ parent.setLayout( new GridLayout(1,false) );
+
+ createToolbar( parent );
+
+ super.createPartControl( parent );
+
+ Control control = parent.getChildren()[1];
+ control.setLayoutData( new GridData( GridData.FILL_BOTH ) );
+
+ }
}
1.4 +6 -83 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorInput.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CriteriaEditorInput.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorInput.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CriteriaEditorInput.java 7 Jul 2006 13:51:10 -0000 1.3
+++ CriteriaEditorInput.java 21 Sep 2006 22:58:37 -0000 1.4
@@ -22,94 +22,22 @@
package org.hibernate.eclipse.criteriaeditor;
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 criteria editor on non file based storage.
*/
-public class CriteriaEditorInput 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 CriteriaEditorInput extends QueryEditorInput {
public CriteriaEditorInput( String storageSource ) {
this( new CriteriaEditorStorage( 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 CriteriaEditorInput( 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;
+ super(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) {
- if(obj instanceof CriteriaEditorInput) {
- return ((CriteriaEditorInput)obj).getName().equals(name);
- }
- return super.equals(obj);
- }
-
- public int hashCode() {
- return name.hashCode();
- }
public String getFactoryId() {
return CriteriaditorInputFactory.ID_FACTORY;
@@ -119,12 +47,7 @@
CriteriaditorInputFactory.saveState( memento, this );
}
- public void setQuery(String query) {
- ((CriteriaEditorStorage)storage).setContents(query);
+ public void resetName() {
+ setName( "Criteria: " + getConsoleConfigurationName()==null?"<None>":getConsoleConfigurationName() );
}
-
- public String getConsoleConfigurationName() {
- return ((CriteriaEditorStorage)storage).getConfigurationName();
- }
-
}
1.4 +8 -89 jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorStorage.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CriteriaEditorStorage.java
===================================================================
RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/criteriaeditor/CriteriaEditorStorage.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- CriteriaEditorStorage.java 7 Jul 2006 13:51:10 -0000 1.3
+++ CriteriaEditorStorage.java 21 Sep 2006 22:58:37 -0000 1.4
@@ -21,112 +21,31 @@
*/
package org.hibernate.eclipse.criteriaeditor;
-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.eclipse.core.runtime.Path;
+import org.hibernate.eclipse.console.QueryEditorStorage;
/**
* Storage for Criteria editors without a file
*/
-public class CriteriaEditorStorage implements IStorage {
+public class CriteriaEditorStorage extends QueryEditorStorage {
- private String contents;
- private String nameLabel;
- private String configurationName;
public CriteriaEditorStorage( String source ) {
- this( "", source, source );
+ super(source);
}
public CriteriaEditorStorage( 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() );
+ super(configurationName, name, source );
}
- /**
- * @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 CriteriaEditorStorage(String consoleName, String string) {
+ super(consoleName, "Criteria: " + (consoleName==null?"<None>":consoleName), string);
}
public IPath getFullPath() {
- return new Path("/" + hashCode() + ".crit");
- }
-
- 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;
+ return null;
}
- public void setContents(String query) {
- this.contents = query;
- }
}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list