cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r429228 [3/3] - in /incubator/cayenne/soc/trunk/cayenne-rop/rop-browser: ./ icons/ src/org/apache/cayenne/ropbrowser/ src/org/apache/cayenne/ropbrowser/actions/ src/org/apache/cayenne/ropbrowser/commands/ src/org/apache/cayenne/ropbrowser/f...
Date Mon, 07 Aug 2006 01:52:04 GMT
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementEditPart.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementEditPart.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementEditPart.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementEditPart.java Sun Aug  6 18:52:01 2006
@@ -31,6 +31,7 @@
 import org.apache.cayenne.ropbrowser.figures.ElementFigure;
 import org.apache.cayenne.ropbrowser.model.ModelElement;
 import org.apache.cayenne.ropbrowser.policies.ElementEditPolicy;
+import org.apache.cayenne.ropbrowser.policies.ElementLayoutEditPolicy;
 import org.eclipse.draw2d.ChopboxAnchor;
 import org.eclipse.draw2d.ConnectionAnchor;
 import org.eclipse.draw2d.Figure;
@@ -43,12 +44,9 @@
 import org.eclipse.gef.RequestConstants;
 import org.eclipse.gef.commands.Command;
 import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
-import org.eclipse.gef.requests.CreateConnectionRequest;
-import org.eclipse.gef.requests.ReconnectRequest;
 
 /**
- * Base abstract EditPart class corresponding to org.apache.cayenne.ropbrowser.model.ModelElement.
+ * Base abstract EditPart class corresponding to {@link ModelElement}.
  * EditPart classes whose models extend ModelElement ought to extend this class.
  * 
  * @author Marcel Gordon
@@ -62,6 +60,7 @@
 	/**
 	 * Upon activation, attach to the model element as a property change listener.
 	 */
+	@Override
 	public void activate() {
 		if (!isActive()) {
 			super.activate();
@@ -72,6 +71,7 @@
 	/**
 	 * Upon deactivation, detach from the model element as a property change listener.
 	 */
+	@Override
 	public void deactivate() {
 		if (isActive()) {
 			super.deactivate();
@@ -80,11 +80,13 @@
 	}
 	
 	/**
-	 * Installs a basic edit policy allowing the deletion of elements. Sub-classes should extend.
+	 * Installs a basic edit policy allowing the deletion of elements and drag and drop. Sub-classes should extend.
 	 */
+	@Override
 	protected void createEditPolicies() {
 		// allow removal of the associated model element
 		installEditPolicy(EditPolicy.COMPONENT_ROLE, new ElementEditPolicy());
+		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ElementLayoutEditPolicy());
 	}
 	
 	/**
@@ -125,6 +127,7 @@
 	 * This method should update the visual representation of the EditPart. Sub-classes
 	 * should extend as this implementation handles basic operations such as resize and move.
 	 */
+	@Override
 	protected void refreshVisuals() {
 		Figure tableFigure = (Figure) getFigure();
 		Point location = tableFigure.getLocation();
@@ -146,6 +149,7 @@
 	/**
 	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelSourceConnections()
 	 */
+	@Override
 	protected List getModelSourceConnections() {
 		return getModelCast().getSourceConnections();
 	}
@@ -153,6 +157,7 @@
 	/**
 	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#getModelTargetConnections()
 	 */
+	@Override
 	protected List getModelTargetConnections() {
 		return getModelCast().getTargetConnections();
 	}
@@ -186,16 +191,17 @@
 	}
 	
 	/**
-	 * Handles {@link RequestConstants#REQ_OPEN} and {@link RequestConstants#REQ_DIRECT_EDIT} requests
-	 * to allow scrolling through records and expansion of relationships.
+	 * Executes commands in response to requests.
 	 * 
 	 * @see org.eclipse.gef.EditPart#performRequest(org.eclipse.gef.Request)
 	 */
+	@Override
 	public void performRequest(Request request)
 	{
 		getViewer().getEditDomain().getCommandStack().execute(getCommand(request));
 	}
 	
+	@Override
 	public Command getCommand(Request request) {
 		if (request.getType().equals(HideAction.HIDE_REQUEST)) {
 			return new HideElementCommand(this.getModelCast());
@@ -210,9 +216,5 @@
 			return new ExistingObjectCommand(this.getModelCast(), ((ExistingObjectRequest) request).getSelectedObject());
 		}
 		return super.getCommand(request); 
-	}
-
-	public boolean isRoot() {
-		return getModelCast().isRoot();
 	}
 }

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/SingleEditPart.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/SingleEditPart.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/SingleEditPart.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/SingleEditPart.java Sun Aug  6 18:52:01 2006
@@ -16,58 +16,34 @@
  */
 package org.apache.cayenne.ropbrowser.parts;
 
-import java.beans.PropertyChangeEvent;
-
 import org.apache.cayenne.ropbrowser.actions.DeleteAction;
 import org.apache.cayenne.ropbrowser.commands.ContractRelationshipCommand;
-import org.apache.cayenne.ropbrowser.commands.ExistingObjectCommand;
-import org.apache.cayenne.ropbrowser.commands.ExistingObjectRequest;
-import org.apache.cayenne.ropbrowser.commands.HideElementCommand;
-import org.apache.cayenne.ropbrowser.commands.ExpandRelationshipCommand;
 import org.apache.cayenne.ropbrowser.commands.DeleteObjectCommand;
-import org.apache.cayenne.ropbrowser.figures.ElementFigure;
+import org.apache.cayenne.ropbrowser.commands.ExpandRelationshipCommand;
 import org.apache.cayenne.ropbrowser.figures.SingleFigure;
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
 import org.apache.cayenne.ropbrowser.model.Connection;
-import org.apache.cayenne.ropbrowser.model.ModelElement;
 import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
 import org.apache.cayenne.ropbrowser.model.SingleModelElement;
-import org.apache.cayenne.ropbrowser.policies.SingleDirectEditPolicy;
-import org.apache.cayenne.ropbrowser.policies.SingleSelectionPolicy;
 import org.eclipse.draw2d.ActionEvent;
 import org.eclipse.draw2d.ActionListener;
 import org.eclipse.draw2d.Button;
 import org.eclipse.draw2d.ButtonModel;
 import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.EditPart;
 import org.eclipse.gef.EditPolicy;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.commands.Command;
 import org.objectstyle.cayenne.map.Relationship;
 
 /**
- * EditPart for the {@link CollectionModelElement} class. Allows
- * scrolling through records and expansion of relationships.
+ * {@link EditPart} for the {@link SingleModelElement} class. Allows the expansion
+ * of relationships.
  * 
  * @author Marcel Gordon
  */
 public class SingleEditPart extends ElementEditPart implements ActionListener {
 	
-	/**
-	 * Extends super to allow scrolling through records on double-click and
-	 * expansion of relationships on single-click.
-	 * 
-	 * @see ElementEditPart#createEditPolicies()
-	 */
-	protected void createEditPolicies() {
-		super.createEditPolicies();
-		
-		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SingleSelectionPolicy());
-		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new SingleDirectEditPolicy());
-	}
-		
-	/**
-	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
-	 */
+	@Override
 	protected IFigure createFigure() {
 		
 		SingleFigure figure = new SingleFigure(this);
@@ -79,6 +55,7 @@
 		return (SingleModelElement) getModel();
 	}
 
+	@Override
 	public Command getCommand(Request request) {
 		if (request.getType().equals(DeleteAction.DELETE_REQUEST)) {
 			return new DeleteObjectCommand(this.getModelCast());
@@ -86,6 +63,10 @@
 		return super.getCommand(request); 
 	}
 
+	/**
+	 * Handles action events from its figure's relationship buttons,
+	 * expanding or contracting a relationship.
+	 */
 	public void actionPerformed(ActionEvent event) {
 		ButtonModel buttonModel = ((Button) event.getSource()).getModel();
 		if (buttonModel.isSelected()) {
@@ -96,6 +77,12 @@
 		}
 	}
 	
+	/**
+	 * Check if a given relationship has been expanded or not (ie
+	 * whether there is a connection to represent the given relationship).
+	 * @param relationship the relationship sought
+	 * @return true if the relationship is represented by a connection; false otherwise
+	 */
 	public boolean isRelationshipExpanded(Relationship relationship) {
 		for (Connection conn : getModelCast().getSourceConnections()) {
 			if (conn instanceof RelationshipConnection) {
@@ -107,6 +94,12 @@
 		return false;
 	}
 	
+	/**
+	 * Returns the RelationshipConnection which represents the specified Relationship,
+	 * if the relationship has been expanded.
+	 * @param relationship the relationship which is sought
+	 * @return the {@link RelationshipConnection} which represents the given {@link Relationship}, or null
+	 */
 	protected RelationshipConnection getRelationshipConnection(Relationship relationship) {
 		for (Connection conn : getModelCast().getSourceConnections()) {
 			if (conn instanceof RelationshipConnection) {

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionDirectEditPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionDirectEditPolicy.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionDirectEditPolicy.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionDirectEditPolicy.java Sun Aug  6 18:52:01 2006
@@ -23,7 +23,7 @@
 import org.eclipse.gef.requests.DirectEditRequest;
 
 /**
- * An empty {@link org.eclipse.gef.editpolicies.DirectEditPolicy}.
+ * Provides a {@link PopOutCommand} in response to a single click.
  * 
  * @author Marecl Gordon
  */

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionSelectionPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionSelectionPolicy.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionSelectionPolicy.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionSelectionPolicy.java Sun Aug  6 18:52:01 2006
@@ -17,6 +17,7 @@
 package org.apache.cayenne.ropbrowser.policies;
 
 import org.apache.cayenne.ropbrowser.commands.NextObjectCommand;
+import org.apache.cayenne.ropbrowser.commands.PopOutCommand;
 import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
 import org.eclipse.gef.Request;
 import org.eclipse.gef.RequestConstants;
@@ -24,7 +25,8 @@
 import org.eclipse.gef.editpolicies.SelectionEditPolicy;
 
 /**
- * An empty {@link org.eclipse.gef.editpolicies.SelectionEditPolicy}.
+ * Provides a {@link NextObjectCommand} in response to {@link RequestConstants#REQ_OPEN},
+ * produced on a double click. 
  * 
  * @author Marcel Gordon
  */
@@ -36,12 +38,15 @@
 		this.element = element;
 	}
 	
+	@Override
 	protected void showSelection() {
 	}
 	
+	@Override
 	protected void hideSelection() {
 	}
 	
+	@Override
 	public Command getCommand(Request request) {
 		if (request.getType().equals(RequestConstants.REQ_OPEN)) {
 			return new NextObjectCommand(element);

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementEditPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementEditPolicy.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementEditPolicy.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementEditPolicy.java Sun Aug  6 18:52:01 2006
@@ -34,6 +34,7 @@
 	/**
 	 * @see org.eclipse.gef.editpolicies.ComponentEditPolicy#createDeleteCommand(org.eclipse.gef.requests.GroupRequest)
 	 */
+	@Override
 	protected Command createDeleteCommand(GroupRequest deleteRequest) {
 		Object parent = getHost().getParent().getModel();
 		Object child = getHost().getModel();

Added: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementLayoutEditPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementLayoutEditPolicy.java?rev=429228&view=auto
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementLayoutEditPolicy.java (added)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementLayoutEditPolicy.java Sun Aug  6 18:52:01 2006
@@ -0,0 +1,67 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.cayenne.ropbrowser.policies;
+
+import org.apache.cayenne.ropbrowser.commands.ExistingObjectCommand;
+import org.apache.cayenne.ropbrowser.model.ModelElement;
+import org.apache.cayenne.ropbrowser.parts.ElementEditPart;
+import org.apache.cayenne.ropbrowser.parts.SingleEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy;
+import org.eclipse.gef.requests.CreateRequest;
+
+/**
+ * Provides commands for drag and drop of elements.
+ * 
+ * @author Marcel Gordon
+ */
+public class ElementLayoutEditPolicy extends OrderedLayoutEditPolicy {
+
+	@Override
+	protected Command createAddCommand(EditPart child, EditPart after) {
+		if (!(child instanceof SingleEditPart))
+			return null;
+
+		ModelElement toMove = (ModelElement) child.getModel();
+		
+		ModelElement host = (ModelElement) ((ElementEditPart) getHost()).getModel();
+		
+		if (toMove.getName().equals(host.getName())) {
+			ExistingObjectCommand command = new ExistingObjectCommand(host, toMove.getCurrentObject());
+			return command;
+		}
+		
+		return null;
+	}
+
+	@Override
+	protected Command createMoveChildCommand(EditPart child, EditPart after) {
+		return null;
+	}
+
+	@Override
+	protected EditPart getInsertionReference(Request request) {
+		return null;
+	}
+
+	@Override
+	protected Command getCreateCommand(CreateRequest request) {
+		return null;
+	}
+
+}

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementXYLayoutEditPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementXYLayoutEditPolicy.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementXYLayoutEditPolicy.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementXYLayoutEditPolicy.java Sun Aug  6 18:52:01 2006
@@ -17,7 +17,6 @@
 
 import org.apache.cayenne.ropbrowser.commands.ElementSetConstraintCommand;
 import org.apache.cayenne.ropbrowser.model.ModelElement;
-import org.apache.cayenne.ropbrowser.parts.ElementDiagramEditPart;
 import org.apache.cayenne.ropbrowser.parts.ElementEditPart;
 import org.eclipse.draw2d.Figure;
 import org.eclipse.draw2d.IFigure;
@@ -33,15 +32,19 @@
 import org.eclipse.gef.requests.CreateRequest;
 
 /**
- * An edit policy handling the layout of elements.
+ * An edit policy handling the layout of elements in manual layout mode.
  * 
+ * Adapted from Phil Zoio's <a href="http://www.eclipse.org/articles/Article-GEF-editor/gef-schema-editor.html">Schema Editor example</a>.
+ * 
+ * @author Phil Zoio
  * @author Marcel Gordon
  */
 public class ElementXYLayoutEditPolicy extends XYLayoutEditPolicy {
 	
-	/**
+	/** 
 	 * @see ConstrainedLayoutEditPolicy#createChangeConstraintCommand(ChangeBoundsRequest, EditPart, Object)
 	 */
+	@Override
 	protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
 			EditPart child, Object constraint) {
 		if (!(child instanceof ElementEditPart))
@@ -49,9 +52,9 @@
 		if (!(constraint instanceof Rectangle))
 			return null;
 
-		ElementEditPart tablePart = (ElementEditPart) child;
-		ModelElement table = (ModelElement) tablePart.getModel();
-		Figure figure = (Figure) tablePart.getFigure();
+		ElementEditPart elementEditPart = (ElementEditPart) child;
+		ModelElement element = (ModelElement) elementEditPart.getModel();
+		Figure figure = (Figure) elementEditPart.getFigure();
 		Rectangle oldBounds = figure.getBounds();
 		Rectangle newBounds = (Rectangle) constraint;
 
@@ -60,7 +63,7 @@
 		if (oldBounds.height != newBounds.height && newBounds.height != -1)
 			return null;
 
-		ElementSetConstraintCommand command = new ElementSetConstraintCommand(table, oldBounds.getCopy(), newBounds.getCopy());
+		ElementSetConstraintCommand command = new ElementSetConstraintCommand(element, oldBounds.getCopy(), newBounds.getCopy());
 		return command;
 	}
 	
@@ -68,6 +71,7 @@
 	 * Returns the current bounds as the constraint if none can be found in the
 	 * figures Constraint object
 	 */
+	@Override
 	public Rectangle getCurrentConstraintFor(GraphicalEditPart child)
 	{
 		IFigure fig = child.getFigure();
@@ -82,6 +86,7 @@
 	/**
 	 * @see ConstrainedLayoutEditPolicy#createChangeConstraintCommand(EditPart, Object)
 	 */
+	@Override
 	protected Command createChangeConstraintCommand(EditPart child,
 			Object constraint) {
 		return null;
@@ -90,6 +95,7 @@
 	/**
 	 * @see LayoutEditPolicy#getCreateCommand(CreateRequest)
 	 */
+	@Override
 	protected Command getCreateCommand(CreateRequest request) {
 		return null;
 	}
@@ -97,6 +103,7 @@
 	/**
 	 * @see LayoutEditPolicy#getDeleteDependantCommand(org.eclipse.gef.Request)
 	 */
+	@Override
 	protected Command getDeleteDependantCommand(Request request) {
 		return null;
 	}

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SelectionHandlesEditPolicy.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SelectionHandlesEditPolicy.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SelectionHandlesEditPolicy.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SelectionHandlesEditPolicy.java Sun Aug  6 18:52:01 2006
@@ -24,7 +24,8 @@
 import org.eclipse.gef.requests.CreateRequest;
 
 /**
- * An edit policy handling the layout of elements.
+ * An edit policy handling the layout of elements. Used to solely to
+ * ensure that selection handles appear in auto layout mode.
  * 
  * @author Marcel Gordon
  */

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/views/ControlPanelView.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/views/ControlPanelView.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/views/ControlPanelView.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/views/ControlPanelView.java Sun Aug  6 18:52:01 2006
@@ -24,6 +24,8 @@
 import org.apache.cayenne.ropbrowser.ObjectEditorInput;
 import org.apache.cayenne.ropbrowser.ROPBrowserPlugin;
 import org.apache.cayenne.ropbrowser.wizards.SelectQueryWizard;
+import org.apache.cayenne.ropbrowser.wizards.SelectParametersPage.Operator;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
@@ -32,10 +34,9 @@
 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.Display;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IEditorPart;
+import org.eclipse.swt.widgets.Group;
 import org.eclipse.ui.IEditorReference;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
@@ -47,6 +48,7 @@
 import org.objectstyle.cayenne.ObjectContext;
 import org.objectstyle.cayenne.exp.Expression;
 import org.objectstyle.cayenne.exp.ExpressionFactory;
+import org.objectstyle.cayenne.exp.parser.ASTObjPath;
 import org.objectstyle.cayenne.map.EntityResolver;
 import org.objectstyle.cayenne.map.ObjEntity;
 import org.objectstyle.cayenne.query.NamedQuery;
@@ -55,200 +57,225 @@
 import org.objectstyle.cayenne.util.Util;
 
 /**
- * An Eclipse view for connecting to the Cayenne web service and launching queries.
+ * An Eclipse view for connecting to the Cayenne web service and launching queries
+ * in {@link ObjectEditor}s. Allows running of {@link NamedQuery} or {@link SelectQuery} with
+ * parameters, and can display the results in one editor or many.
  * 
  * @author Marcel Gordon
  */
 public class ControlPanelView extends ViewPart implements SelectionListener {
-
+	
 	/** ID of the view */
 	public static final String ID = "org.apache.cayenne.ropbrowser.views.ControlPanelView";
 
 	/** name of the preference used to store the server last connected to */
 	private static final String PREF_SERVER = "CONTROL_PANEL_SERVER";
 
-	/** toolkit for creating of form elements */
-	private FormToolkit	toolkit;
-	private Form form;
-	/** server to connect to */
-	private CCombo serverCombo;
+	/** manages connections to the server */
+	private ConnectionManager connectionManager;
+	/** dropdown for selecting a named query to run */
+	private Combo namedQueryCombo;
+	
 	/** button initiates connection */
 	private Button connectButton;
+	/**
+	 * Checkbox to specify if the query should be displayed
+	 * in a new diagram or an existing one
+	 */
+	private Button newDiagramButton;
+	/**
+	 * button for opening a {@link SelectQueryWizard} to specify
+	 * parameters for the query
+	 */
+	private Button parametersButton;
 	
-	/** dropdown for selecting a query to run */
-	private CCombo namedQueryCombo;
-	/** button to launch query editor */
+	/** button to run named query */
 	private Button runNamedQueryButton;
-	
-	private CCombo selectQueryCombo;
-	private Button parametersButton;
+	/**
+	 * button to run the select query
+	 */
 	private Button runSelectQueryButton;
+	/**
+	 * combo for selecting an entity to run a select query on
+	 */
+	private Combo selectQueryCombo;
 	
-	private Button newDiagramButton;
+	/**
+	 * Wizard used to specify parameters for select queries.
+	 */
+	private SelectQueryWizard selectWizard;
 
-	/** manages connections to the server */
-	private ConnectionManager connectionManager;
-	
-	private SelectQueryWizard selectWizard; 
+	/** server to connect to */
+	private Combo serverCombo; 
 	
 	public ControlPanelView() {
 		connectionManager = ConnectionManager.getInstance();
 	}
 	
+	private void connectToServer() {
+		// connect to the specified server
+		namedQueryCombo.removeAll();
+		
+		// if this address isn't in the dropdown yet, add it
+		if (serverCombo.indexOf(serverCombo.getText()) == -1) {
+			serverCombo.add(serverCombo.getText());
+		}
+		
+		ROPBrowserPlugin.getDefault().getPluginPreferences().setValue(PREF_SERVER, serverCombo.getText());
+		
+		ObjectContext currentContext = null;
+		
+		try {
+			currentContext = connectionManager.getNewObjectContext(serverCombo.getText());
+		}
+		catch (Exception ex) {
+			ROPBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, ROPBrowserPlugin.ID, Status.OK, ex.getMessage(), ex));
+		}
+		
+		if (currentContext != null) {
+			// get all the queries for this connection
+			EntityResolver entityResolver = currentContext.getEntityResolver();
+			Iterator i = entityResolver.getQueries().iterator();
+			while (i.hasNext()) {
+				namedQueryCombo.add(((Query)i.next()).getName());
+			}
+			// set the server address as user data for use in running queries
+			namedQueryCombo.setData(serverCombo.getText());
+			
+			// get all the entities in this context for use as select queries
+			i = entityResolver.getObjEntities().iterator();
+			while (i.hasNext()) {
+				selectQueryCombo.add(((ObjEntity)i.next()).getName());
+			}
+			// set the server address as user data for use in running queries
+			selectQueryCombo.setData(serverCombo.getText());
+		}
+	}
+	
 	/**
 	 * Create the controls for the view. Called internally.
 	 */
+	@Override
 	public void createPartControl(Composite parent) {
-		toolkit = new FormToolkit(parent.getDisplay());
-		form = toolkit.createForm(parent);
-		
 		ColumnLayout layout = new ColumnLayout();
 		layout.maxNumColumns = 4;
-		form.getBody().setLayout(layout);
+		parent.setLayout(layout);
 		
 		// Create the server section
-		Section serverSection = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.EXPANDED);
-		serverSection.setText("Server");
-		Composite serverComposite = toolkit.createComposite(serverSection);
-		serverComposite.setLayout(new GridLayout());
+		Group serverGroup = new Group(parent, SWT.NULL);
+		serverGroup.setText("Server");
+		serverGroup.setLayout(new GridLayout());
 		
-		serverCombo = new CCombo(serverComposite, SWT.FLAT);
+		serverCombo = new Combo(serverGroup, SWT.FLAT | SWT.BORDER);
 		serverCombo.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
 		String defaultServer = ROPBrowserPlugin.getDefault().getPluginPreferences().getString(PREF_SERVER);
 		if (defaultServer != null) {
 			serverCombo.add(defaultServer);
 			serverCombo.setText(defaultServer);
 		}
-		connectButton = toolkit.createButton(serverComposite, "Connect", SWT.PUSH);
+		connectButton = new Button(serverGroup, SWT.PUSH);
+		connectButton.setText("Connect");
 		connectButton.addSelectionListener(this);
 		
-		serverSection.setClient(serverComposite);
-		
 		// create the named query section
-		Section namedQuerySection = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.EXPANDED);
-		namedQuerySection.setText("Named Query");
-		Composite namedQueryComposite = toolkit.createComposite(namedQuerySection);
-		namedQueryComposite.setLayout(new GridLayout());
+		Group namedQueryGroup = new Group(parent, SWT.NULL);
+		namedQueryGroup.setText("Named Query");
+		namedQueryGroup.setLayout(new GridLayout());
 		
-		namedQueryCombo = new CCombo(namedQueryComposite, SWT.READ_ONLY | SWT.FLAT);
+		namedQueryCombo = new Combo(namedQueryGroup, SWT.READ_ONLY | SWT.FLAT | SWT.BORDER);
 		namedQueryCombo.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
 		
-		runNamedQueryButton = toolkit.createButton(namedQueryComposite, "Run", SWT.PUSH);
+		runNamedQueryButton = new Button(namedQueryGroup, SWT.PUSH);
+		runNamedQueryButton.setText("Run");
 		runNamedQueryButton.addSelectionListener(this);
 		
-		namedQuerySection.setClient(namedQueryComposite);
-		
 		// create the select query section
-		Section selectQuerySection = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.EXPANDED);
-		selectQuerySection.setText("Select Query");
-		Composite selectQueryComposite = toolkit.createComposite(selectQuerySection);
-		selectQueryComposite.setLayout(new GridLayout());
+		Group selectQueryGroup = new Group(parent, SWT.NULL);
+		selectQueryGroup.setText("Select Query");
+		selectQueryGroup.setLayout(new GridLayout());
 		
-		selectQueryCombo = new CCombo(selectQueryComposite, SWT.READ_ONLY | SWT.FLAT);
+		selectQueryCombo = new Combo(selectQueryGroup, SWT.READ_ONLY | SWT.FLAT | SWT.BORDER);
 		selectQueryCombo.setLayoutData(new GridData(SWT.FILL, SWT.NULL, true, false));
 		
-		parametersButton = toolkit.createButton(selectQueryComposite, "Parameters...", SWT.PUSH);
+		parametersButton =  new Button(selectQueryGroup, SWT.PUSH);
+		parametersButton.setText("Parameters...");
 		parametersButton.addSelectionListener(this);
 		
-		runSelectQueryButton = toolkit.createButton(selectQueryComposite, "Run", SWT.PUSH);
+		runSelectQueryButton = new Button(selectQueryGroup, SWT.PUSH);
+		runSelectQueryButton.setText("Run");
 		runSelectQueryButton.addSelectionListener(this);
 		
-		selectQuerySection.setClient(selectQueryComposite);
-		
 		// create the misc section
-		Section miscSection = toolkit.createSection(form.getBody(), Section.TITLE_BAR | Section.EXPANDED);
-		miscSection.setText("Other Settings");
-		Composite miscComposite = toolkit.createComposite(miscSection);
-		miscComposite.setLayout(new GridLayout());
+		Group miscGroup = new Group(parent, SWT.NULL);
+		miscGroup.setText("Other Settings");
+		miscGroup.setLayout(new GridLayout());
 		
-		newDiagramButton = toolkit.createButton(miscComposite, "Display in new editor", SWT.CHECK);
+		newDiagramButton = new Button(miscGroup, SWT.CHECK);
+		newDiagramButton.setText("Display in new editor");
 		newDiagramButton.setSelection(true);
 		
-		miscSection.setClient(miscComposite);
-		
-		toolkit.paintBordersFor(form.getBody());
-		toolkit.paintBordersFor(serverComposite);
-		toolkit.paintBordersFor(namedQueryComposite);
-		toolkit.paintBordersFor(selectQueryComposite);
-		toolkit.paintBordersFor(miscComposite);
-		
-		form.getBody().pack();
-	}
-	
-	@Override
-	public void setFocus() {
-		form.setFocus();
+		parent.pack();
 	}
 
 	/**
-	 * Handle connections to the server and running of queries.
+	 * Display the results of a query in the editor. This will be a new editor only
+	 * if 'open in new editor' is specified.
+	 * @param context the context in which the query was run
+	 * @param address the address of the server from which the context comes
+	 * @param matches the results of the query
 	 */
-	public void widgetSelected(SelectionEvent e) {
-		if (e.getSource() == connectButton) {
-			namedQueryCombo.removeAll();
-			
-			if (serverCombo.indexOf(serverCombo.getText()) == -1) {
-				serverCombo.add(serverCombo.getText());
-			}
-			
-			ROPBrowserPlugin.getDefault().getPluginPreferences().setValue(PREF_SERVER, serverCombo.getText());
-			
-			ObjectContext currentContext = connectionManager.getNewObjectContext(serverCombo.getText());
-					
-			// get all the queries for this connection
-			EntityResolver entityResolver = currentContext.getEntityResolver();
-			Iterator i = entityResolver.getQueries().iterator();
-			while (i.hasNext()) {
-				namedQueryCombo.add(((Query)i.next()).getName());
-			}
-			namedQueryCombo.setData(serverCombo.getText());
-			
-			i = entityResolver.getObjEntities().iterator();
-			while (i.hasNext()) {
-				selectQueryCombo.add(((ObjEntity)i.next()).getName());
+	private void displayInEditor(ObjectContext context, String address, Object matches) {
+		try {
+			ObjectEditor editor;
+			if (newDiagramButton.getSelection()) {
+				editor = getNewEditor(context, address);
 			}
-			selectQueryCombo.setData(serverCombo.getText());
-		}
-		else if (e.getSource() == runNamedQueryButton) {
-			if (namedQueryCombo.indexOf(namedQueryCombo.getText()) != -1) {
-				ObjectContext context = getObjectContext((String) namedQueryCombo.getData());
-				NamedQuery select = new NamedQuery(namedQueryCombo.getText());
-				if (context != null) {
-					Object matches = context.performQuery(select);
-				
-					displayInEditor(context, (String) namedQueryCombo.getData(), matches);
+			else {
+				editor = getExistingEditor(address);
+				if (editor == null) {
+					editor = getNewEditor(context, address);
 				}
 			}
+			editor.getDiagram().addRootElement(matches);
+		} catch (PartInitException ex) {
+			ROPBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, ROPBrowserPlugin.ID, Status.OK, ex.getMessage(), ex));
 		}
-		else if (e.getSource() == parametersButton && selectQueryCombo.indexOf(selectQueryCombo.getText()) != -1) {
-			if (selectWizard == null) {
-				selectWizard = new SelectQueryWizard(connectionManager.getNewObjectContext((String) selectQueryCombo.getData()), selectQueryCombo.getText(), SelectQueryWizard.RETURN_PARAMS);
-			}
-			WizardDialog dialog = new WizardDialog(getViewSite().getShell(), selectWizard);
-			dialog.create();
-			dialog.open();
-		}
-		else if (e.getSource() == runSelectQueryButton) {
-			if (selectQueryCombo.indexOf(selectQueryCombo.getText()) != -1) {
-				ObjectContext context = getObjectContext((String) selectQueryCombo.getData());
-				Object matches;
-				if (selectWizard != null && selectWizard.getEntityName().equals(selectQueryCombo.getText())) {
-					String [] paramNames = selectWizard.getParameterNames();
-					Object [] paramValues = selectWizard.getParameterValues();
-					
-					matches = context.performQuery(new SelectQuery(selectQueryCombo.getText(), ExpressionFactory.matchAllExp(Util.toMap(paramNames, paramValues), Expression.EQUAL_TO)));
-				}
-				else {
-					matches = context.performQuery(new SelectQuery(selectQueryCombo.getText()));
+	}
+
+	/**
+	 * Find an existing editor
+	 * @param address the address which the editor's context comes from
+	 * @return the editor if one exists with the given address, or null
+	 */
+	private ObjectEditor getExistingEditor(String address) {
+		for (IEditorReference editor : getViewSite().getPage().findEditors(null, ObjectEditor.ID, IWorkbenchPage.MATCH_ID)) {
+			try {
+				ObjectEditorInput input = (ObjectEditorInput) editor.getEditorInput();
+				if (input.getServerAddress().equals(address)) {
+					return (ObjectEditor) editor.getEditor(false);
 				}
-				
-				displayInEditor(context, (String) selectQueryCombo.getData(), matches);
+			} catch (PartInitException ex) {
+				ROPBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, ROPBrowserPlugin.ID, Status.OK, ex.getMessage(), ex));
 			}
 		}
+		return null;
+	}
+
+	/**
+	 * Open a new editor to display the results of a query
+	 * @param context the context in which the query was run
+	 * @param address the address of the server from which the context comes
+	 * @return the new editor
+	 */
+	private ObjectEditor getNewEditor(ObjectContext context, String address) throws PartInitException {
+		return (ObjectEditor) getViewSite().getPage().openEditor(new ObjectEditorInput(context, address), ObjectEditor.ID, true);
 	}
 
+	/**
+	 * @return the object context for the given address. This will be new
+	 * only if 'open in new editor' is selected.
+	 */
 	private ObjectContext getObjectContext(String address) {
-		// TODO more efficient method?
 		ObjectContext context;
 		if (newDiagramButton.getSelection()) {
 			context = this.connectionManager.getNewObjectContext(address);
@@ -265,44 +292,82 @@
 		return context;
 	}
 
-	private void displayInEditor(ObjectContext context, String address, Object matches) {
-		// TODO new context option
-		// TODO XMPP on/off option
-		try {
-			ObjectEditor editor;
-			if (newDiagramButton.getSelection()) {
-				editor = getNewEditor(context, address);
-			}
-			else {
-				editor = getExistingEditor(address);
-				if (editor == null) {
-					editor = getNewEditor(context, address);
-				}
+	private void openParametersWizard() {
+		selectWizard = new SelectQueryWizard(connectionManager.getNewObjectContext((String) selectQueryCombo.getData()), selectQueryCombo.getText(), SelectQueryWizard.RETURN_PARAMS);
+		WizardDialog dialog = new WizardDialog(getViewSite().getShell(), selectWizard);
+		dialog.create();
+		dialog.open();
+	}
+
+	private void runNamedQuery() {
+		if (namedQueryCombo.indexOf(namedQueryCombo.getText()) != -1) {
+			ObjectContext context = getObjectContext((String) namedQueryCombo.getData());
+			NamedQuery select = new NamedQuery(namedQueryCombo.getText());
+			if (context != null) {
+				Object matches = context.performQuery(select);
+			
+				displayInEditor(context, (String) namedQueryCombo.getData(), matches);
 			}
-			editor.getDiagram().addRootElement(matches);
-		} catch (PartInitException ex) {
-			System.out.println(ex.getMessage());
 		}
 	}
-	
-	private ObjectEditor getNewEditor(ObjectContext context, String address) throws PartInitException {
-		return (ObjectEditor) getViewSite().getPage().openEditor(new ObjectEditorInput(context, address), ObjectEditor.ID, true);
-	}
 
-	private ObjectEditor getExistingEditor(String address) {
-		for (IEditorReference editor : getViewSite().getPage().findEditors(null, ObjectEditor.ID, IWorkbenchPage.MATCH_ID)) {
-			try {
-				ObjectEditorInput input = (ObjectEditorInput) editor.getEditorInput();
-				if (input.getServerAddress().equals(address)) {
-					return (ObjectEditor) editor.getEditor(false);
+	private void runSelectQuery() {
+		if (selectQueryCombo.indexOf(selectQueryCombo.getText()) != -1) {
+			ObjectContext context = getObjectContext((String) selectQueryCombo.getData());
+			Object matches;
+			// check to see if parameters have been specified for this entity
+			if (selectWizard != null && selectWizard.getEntityName().equals(selectQueryCombo.getText())) {				
+				Expression qual = null;
+				HashMap<String, Object> paramMap = selectWizard.getParametersPage().getParameterMap();
+				HashMap<String, Operator> operatorMap = selectWizard.getParametersPage().getOperatorMap();
+				
+				Iterator<String> paramNames = paramMap.keySet().iterator();
+				while (paramNames.hasNext()) {
+					String paramName = paramNames.next();
+					Expression current = ExpressionFactory.expressionOfType(operatorMap.get(paramName).getCayenneValue());
+					current.setOperand(0, new ASTObjPath(paramName));
+					current.setOperand(1, paramMap.get(paramName));
+					if (qual == null) {
+						qual = current;
+					}
+					else {
+						qual = qual.andExp(current);
+					}
 				}
-			} catch (PartInitException e) {
-				System.out.println("Error restoring editor: " + e.getMessage());
+				
+				matches = context.performQuery(new SelectQuery(selectQueryCombo.getText(), qual));
+			}
+			else {
+				matches = context.performQuery(new SelectQuery(selectQueryCombo.getText()));
 			}
+			
+			displayInEditor(context, (String) selectQueryCombo.getData(), matches);
 		}
-		return null;
 	}
 
 	public void widgetDefaultSelected(SelectionEvent e) {
+	}
+
+	/**
+	 * Handle connections to the server and running of queries.
+	 */
+	public void widgetSelected(SelectionEvent e) {
+		if (e.getSource() == connectButton) {
+			connectToServer();
+		}
+		else if (e.getSource() == runNamedQueryButton) {
+			runNamedQuery();
+		}
+		else if (e.getSource() == parametersButton && selectQueryCombo.indexOf(selectQueryCombo.getText()) != -1) {
+			openParametersWizard();
+			runSelectQuery();
+		}
+		else if (e.getSource() == runSelectQueryButton) {
+			runSelectQuery();
+		}
+	}
+
+	@Override
+	public void setFocus() {
 	}
 }

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectObjectPage.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectObjectPage.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectObjectPage.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectObjectPage.java Sun Aug  6 18:52:01 2006
@@ -16,17 +16,14 @@
 package org.apache.cayenne.ropbrowser.wizards;
 
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.cayenne.ropbrowser.model.AbstractObject;
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.jface.resource.ImageDescriptor;
+import org.apache.cayenne.ropbrowser.wizards.SelectParametersPage.Operator;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.ControlEvent;
 import org.eclipse.swt.events.ControlListener;
 import org.eclipse.swt.events.SelectionEvent;
@@ -34,43 +31,52 @@
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
 import org.objectstyle.cayenne.ObjectContext;
 import org.objectstyle.cayenne.exp.Expression;
 import org.objectstyle.cayenne.exp.ExpressionFactory;
+import org.objectstyle.cayenne.exp.parser.ASTObjPath;
 import org.objectstyle.cayenne.map.EntityResolver;
 import org.objectstyle.cayenne.map.ObjAttribute;
 import org.objectstyle.cayenne.map.ObjEntity;
-import org.objectstyle.cayenne.query.NamedQuery;
-import org.objectstyle.cayenne.query.Query;
 import org.objectstyle.cayenne.query.SelectQuery;
 import org.objectstyle.cayenne.util.Util;
 
+/**
+ * {@link WizardPage} for {@link SelectQueryWizard} which displays a list of objects
+ * from a {@link SelectQuery} and allows the user to select one. 
+ * 
+ * @author Marcel Gordon
+ */
 public class SelectObjectPage extends WizardPage implements SelectionListener, ControlListener {
 	
+	/**
+	 * The context in which to run the query
+	 */
 	private ObjectContext context;
 	
+	/**
+	 * The name of the entity involved in the query
+	 */
 	private String entityName;
 	
+	/**
+	 * Table in which to display objects
+	 */
 	private Table objectTable;
 	
-	private String[] paramNames;
-	private Object[] paramValues;
-
 	public SelectObjectPage(String pageName, ObjectContext context, String entityName) {
 		super(pageName);
 		this.context = context;
 		this.entityName = entityName;
 	}
 
+	/**
+	 * Create the controls used in displaying the page.
+	 */
 	public void createControl(Composite parent) {
 		setTitle("Select object");
 		setMessage("Select the desired object from the list");
@@ -109,6 +115,9 @@
 	public void widgetDefaultSelected(SelectionEvent e) {
 	}
 
+	/**
+	 * Handle selection of an object in the table.
+	 */
 	public void widgetSelected(SelectionEvent e) {
 		TableItem[] selection = objectTable.getSelection();
 		if (selection != null && selection.length > 0) {
@@ -116,6 +125,9 @@
 		}
 	}
 	
+	/**
+	 * Resize the table when the dialog is resized
+	 */
 	public void controlResized(ControlEvent e) {		
 		// handle the sizing of the table columns
 		Point size = objectTable.getSize();
@@ -125,38 +137,47 @@
 		} 
 
 		for (TableColumn col : objectTable.getColumns()) {
-			col.setWidth((int) size.x/3);
+			col.setWidth(size.x/3);
 		}
 	}
 
 	public void controlMoved(ControlEvent e) {
 	}
 
+	/**
+	 * Run the {@link SelectQuery} to fill the table with data
+	 */
 	public void onEnterPage() {
-		if (getNewValues()) {
-			objectTable.removeAll();
-			
-			EntityResolver entityResolver = context.getEntityResolver();
-			ObjEntity entity = entityResolver.getObjEntity(entityName);
+		objectTable.removeAll();
 			
-			Expression qual = ExpressionFactory.matchAllExp(Util.toMap(paramNames, paramValues), Expression.EQUAL_TO);
-			SelectQuery query = new SelectQuery(entity.getJavaClass(), qual);
-							
-			Object matches = this.context.performQuery(query);
-			
-			if (matches instanceof List) {
-				for (Object o : (List) matches) {
-					AbstractObject abstractObject = (AbstractObject) o;
-					TableItem item = new TableItem(objectTable, SWT.NULL);
-					int i = 0;
-					for (TableColumn col : objectTable.getColumns()) {
-						item.setText(i++, abstractObject.getPropertyValue(col.getText()).toString());
-						item.setData(abstractObject);
-					}
-				}
+		EntityResolver entityResolver = context.getEntityResolver();
+		ObjEntity entity = entityResolver.getObjEntity(entityName);
+		
+		Expression qual = null;
+		HashMap<String, Object> paramMap = ((SelectQueryWizard) getWizard()).getParametersPage().getParameterMap();
+		HashMap<String, Operator> operatorMap = ((SelectQueryWizard) getWizard()).getParametersPage().getOperatorMap();
+		
+		Iterator<String> paramNames = paramMap.keySet().iterator();
+		while (paramNames.hasNext()) {
+			String paramName = paramNames.next();
+			Expression current = ExpressionFactory.expressionOfType(operatorMap.get(paramName).getCayenneValue());
+			current.setOperand(0, new ASTObjPath(paramName));
+			current.setOperand(1, paramMap.get(paramName));
+			if (qual == null) {
+				qual = current;
+			}
+			else {
+				qual = qual.andExp(current);
 			}
-			if (matches instanceof AbstractObject) {
-				AbstractObject abstractObject = (AbstractObject) matches;
+		}
+		
+		SelectQuery query = new SelectQuery(entity.getJavaClass(), qual);
+						
+		Object matches = this.context.performQuery(query);
+		
+		if (matches instanceof List) {
+			for (Object o : (List) matches) {
+				AbstractObject abstractObject = (AbstractObject) o;
 				TableItem item = new TableItem(objectTable, SWT.NULL);
 				int i = 0;
 				for (TableColumn col : objectTable.getColumns()) {
@@ -164,28 +185,21 @@
 					item.setData(abstractObject);
 				}
 			}
-			controlResized(null);
-			if (objectTable.getItemCount() > 0) {
-				objectTable.select(0);
-				objectTable.setFocus();
-				widgetSelected(null);
+		}
+		if (matches instanceof AbstractObject) {
+			AbstractObject abstractObject = (AbstractObject) matches;
+			TableItem item = new TableItem(objectTable, SWT.NULL);
+			int i = 0;
+			for (TableColumn col : objectTable.getColumns()) {
+				item.setText(i++, abstractObject.getPropertyValue(col.getText()).toString());
+				item.setData(abstractObject);
 			}
 		}
-	}
-
-	private boolean getNewValues() {
-		SelectQueryWizard wizard = (SelectQueryWizard) getWizard();
-		String [] newParamNames = wizard.getParameterNames();
-		Object [] newParamValues = wizard.getParameterValues();
-		
-		if (Arrays.equals(paramNames, newParamNames)
-				&& Arrays.equals(paramValues, newParamValues)) {
-			return false;
+		controlResized(null);
+		if (objectTable.getItemCount() > 0) {
+			objectTable.select(0);
+			objectTable.setFocus();
+			widgetSelected(null);
 		}
-		
-		paramNames = newParamNames;
-		paramValues = newParamValues;
-		
-		return true;
 	}
 }

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectParametersPage.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectParametersPage.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectParametersPage.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectParametersPage.java Sun Aug  6 18:52:01 2006
@@ -15,61 +15,131 @@
  */
 package org.apache.cayenne.ropbrowser.wizards;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.jface.resource.ImageDescriptor;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.ComboBoxCellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.TableLayout;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CCombo;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
+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.Display;
 import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Table;
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.swt.widgets.Text;
 import org.objectstyle.cayenne.ObjectContext;
+import org.objectstyle.cayenne.exp.Expression;
 import org.objectstyle.cayenne.map.EntityResolver;
 import org.objectstyle.cayenne.map.ObjAttribute;
 import org.objectstyle.cayenne.map.ObjEntity;
-import org.objectstyle.cayenne.query.NamedQuery;
-import org.objectstyle.cayenne.query.Query;
 
-public class SelectParametersPage extends WizardPage implements SelectionListener, ControlListener {
-	
+/**
+ * {@link WizardPage} for use with {@link SelectQueryWizard} which allows the specification of query parameters.
+ * 
+ * @author Marcel Gordon
+ */
+public class SelectParametersPage extends WizardPage implements SelectionListener {
+	
+	/**
+	 * The context to use when discovering attributes
+	 */
 	private ObjectContext context;
 	
+	/**
+	 * The name of the entity whose attributes are to be parameters.
+	 */
 	private String entityName;
 	
-	private Table attributeTable;
+	/**
+	 * Table of attributes
+	 */
+	private TableViewer attributeTable;
+	/**
+	 * Column for attribute names
+	 */
 	private TableColumn attributeName;
+	/**
+	 * Column for attribute types
+	 */
 	private TableColumn attributeType;
-	
-	private Button setButton;
-	
+	/**
+	 * Column for operator selection
+	 */
+	private TableColumn operator;
+	/**
+	 * Column for specifying parameter value
+	 */
+	private TableColumn value;
+	
+	/**
+	 * Button to clear all values which have been set
+	 */
 	private Button clearAllButton;
 	
-	private Text parameterValue;
-	
+	/**
+	 * Label to display errors
+	 */
 	private Label errorLabel;
+	
+	/**
+	 * Map used to store the names (String) and values (Object) of parameters
+	 */
+	private HashMap<String, Object> paramMap;
+	
+	/** Map used to store the operators mapped to attribute names */
+	private HashMap<String, Operator> operatorMap;
+	
+	/**
+	 * Names for columns in the attribute table
+	 */
+	private static final String[] COLUMN_NAMES = {"Name", "Type", "Operator", "Value"};
+	
+	public enum Operator {
+		EQUAL_TO (Expression.EQUAL_TO),
+		GREATER_THAN (Expression.GREATER_THAN),
+		GREATER_THAN_EQUAL_TO (Expression.GREATER_THAN_EQUAL_TO),
+		LESS_THAN (Expression.LESS_THAN),
+		LESS_THAN_EQUAL_TO (Expression.LESS_THAN_EQUAL_TO);
+		
+		private final int cayenneValue;
+		
+		Operator(int cayenneValue) {
+			this.cayenneValue = cayenneValue;
+		}
+		
+		public int getCayenneValue() {
+			return cayenneValue;
+		}
+	};
 
 	public SelectParametersPage(String pageName, ObjectContext context, String entityName) {
 		super(pageName);
 		this.context = context;
 		this.entityName = entityName;
+		paramMap = new HashMap<String, Object>();
+		operatorMap = new HashMap<String, Operator>();
 	}
 
+	/**
+	 * Create the controls for use on the page
+	 */
 	public void createControl(Composite parent) {
 		setTitle("Enter parameters");
 		setMessage("Select the parameters to use to retrieve a list of objects");
@@ -82,43 +152,57 @@
 		layout.horizontalSpacing = 20;
 		layout.verticalSpacing = 10;
 		layout.numColumns = 2;
-		GridData fillSpan = new GridData(SWT.FILL, SWT.NULL, false, false);
-		fillSpan.horizontalSpan = 2;
-		GridData fillGrab = new GridData(SWT.FILL, SWT.NULL, true, false);
-
-		attributeTable = new Table(base, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
-		attributeTable.setHeaderVisible(true);
-		attributeTable.setLinesVisible(true);
-		attributeTable.setLayoutData(fillSpan);
-		attributeTable.addSelectionListener(this);
-		attributeTable.addControlListener(this);
-		
-		attributeName = new TableColumn(attributeTable, SWT.NULL);
-		attributeName.setText("Attribute Name");
-		attributeType = new TableColumn(attributeTable, SWT.NULL);
-		attributeType.setText("Attribute Type");
+		GridData tableData = new GridData(SWT.FILL, SWT.FILL, true, true);
+		tableData.horizontalSpan = 2;
+		GridData errorLabelData = new GridData(SWT.FILL, SWT.NULL, true, false);
+
+		attributeTable = new TableViewer(base, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
+		attributeTable.setContentProvider(new AttributeTableContentProvider());
+		attributeTable.setLabelProvider(new AttributeTableLabelProvider());
+		attributeTable.setColumnProperties(COLUMN_NAMES);
+		attributeTable.setCellModifier(new AttributeTableCellModifier());
+		CellEditor [] editors = new CellEditor[4];
+		Operator [] operators = Operator.values();
+		String [] opNames = new String[operators.length];
+		for (int i = 0; i < operators.length; i++) {
+			opNames[i] = operators[i].toString();
+		}
+		editors[2] = new ComboBoxCellEditor(attributeTable.getTable(), opNames, SWT.READ_ONLY);
+		editors[3] = new TextCellEditor(attributeTable.getTable());
+		attributeTable.setCellEditors(editors);
+		attributeTable.getTable().setHeaderVisible(true);
+		attributeTable.getTable().setLinesVisible(true);
+		attributeTable.getTable().setLayoutData(tableData);
+		
+		attributeName = new TableColumn(attributeTable.getTable(), SWT.NULL);
+		attributeName.setText(COLUMN_NAMES[0]);
+		attributeType = new TableColumn(attributeTable.getTable(), SWT.NULL);
+		attributeType.setText(COLUMN_NAMES[1]);
+		operator = new TableColumn(attributeTable.getTable(), SWT.NULL);
+		operator.setText(COLUMN_NAMES[2]);
+		value = new TableColumn(attributeTable.getTable(), SWT.NULL);
+		value.setText(COLUMN_NAMES[3]);
+		
+		TableLayout tableLayout = new TableLayout();
+		tableLayout.addColumnData(new ColumnWeightData(2));
+		tableLayout.addColumnData(new ColumnWeightData(2));
+		tableLayout.addColumnData(new ColumnWeightData(1));
+		tableLayout.addColumnData(new ColumnWeightData(2));
+		attributeTable.getTable().setLayout(tableLayout);
 		
 		// get the attributes for this entity
 		EntityResolver entityResolver = context.getEntityResolver();
 		ObjEntity entity = entityResolver.getObjEntity(entityName);
-		Iterator i = entity.getAttributes().iterator();
-		while (i.hasNext()) {
-			TableItem item = new TableItem(attributeTable, SWT.NULL);
-			ObjAttribute attribute = (ObjAttribute) i.next();
-			item.setText(new String[] {attribute.getName(), attribute.getType()});
+		Collection attributes = entity.getAttributes();
+		for (Object o : attributes) {
+			ObjAttribute attribute = (ObjAttribute) o;
+			operatorMap.put(attribute.getName(), Operator.EQUAL_TO);
 		}
-		
-		parameterValue = new Text(base, SWT.SINGLE | SWT.BORDER);
-		parameterValue.setLayoutData(fillGrab);
-		parameterValue.addSelectionListener(this);
-		
-		setButton = new Button(base, SWT.PUSH | SWT.BORDER);
-		setButton.setText("Set");
-		setButton.addSelectionListener(this);
+		attributeTable.setInput(attributes);
 		
 		errorLabel = new Label(base, SWT.NULL);
 		errorLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
-		errorLabel.setLayoutData(fillGrab);
+		errorLabel.setLayoutData(errorLabelData);
 		
 		clearAllButton = new Button(base, SWT.PUSH | SWT.BORDER);
 		clearAllButton.setText("Clear all");
@@ -129,104 +213,165 @@
 		setPageComplete(true);
 	}
 	
+	/**
+	 * Overridden to set page 2 values when next is pressed
+	 */
 	public IWizardPage getNextPage() {
-		SelectObjectPage page2 = ((SelectQueryWizard) getWizard()).getPage2();
+		SelectObjectPage page2 = ((SelectQueryWizard) getWizard()).getObjectPage();
 		page2.onEnterPage();
 		return page2;
 	}
 	
-	// override to avoid getNextPage being called
+	/**
+	 * Overridden to prevent {@link #getNextPage()} being called.
+	 */
+	@Override
 	public boolean canFlipToNextPage() {
 		return isPageComplete() && isNextPage();
 	}
 	
+	/**
+	 * @return true if there is a next page
+	 */
 	private boolean isNextPage() {
 		return (super.getNextPage() != null);
 	}
 
+	/**
+	 * Not used.
+	 */
 	public void widgetDefaultSelected(SelectionEvent e) {
-		if (e.getSource() == parameterValue) {
-			setParameterValue();
-		}
 	}
 
+	/**
+	 * Handles selection events from buttons and table
+	 */
 	public void widgetSelected(SelectionEvent e) {
 		errorLabel.setText("");
-		if (e.getSource() == attributeTable) {
-			TableItem [] selection = attributeTable.getSelection();
-			if (selection[0].getData() != null) {
-				parameterValue.setText(selection[0].getData().toString());
-			}
-			parameterValue.setFocus();
-		}
-		else if (e.getSource() == setButton) {
-			setParameterValue();
+		if (e.getSource() == clearAllButton) {
+			paramMap.clear();
+			attributeTable.refresh();
 		}
-		else if (e.getSource() == clearAllButton) {
-			for (TableItem item : attributeTable.getItems()) {
-				item.setData(null);
-				item.setBackground(attributeTable.getBackground());
+	}
+		
+		// TODO make a util class for converting to and from Strings, use here and AO
+
+	/**
+	 * @return the names and values of the parameters which have been set.
+	 */
+	public HashMap<String, Object> getParameterMap() {
+		return paramMap;
+	}
+	
+	/**
+	 * @return the names of attributes and the operator to be used in the query.
+	 */
+	public HashMap<String, Operator> getOperatorMap() {
+		return operatorMap;
+	}
+	
+	class AttributeTableContentProvider implements IStructuredContentProvider {
+
+		public Object[] getElements(Object inputElement) {
+			if (inputElement instanceof Collection) {
+				return ((Collection) inputElement).toArray(new ObjAttribute[((Collection) inputElement).size()]);
 			}
+			return null;
+		}
+		public void dispose() {
 		}
+
+		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+		}	
 	}
 	
-	private void setParameterValue() {
-		TableItem [] selection = attributeTable.getSelection();
-		if (selection != null && selection.length != 0) {
-			if (parameterValue.getText() != null && parameterValue.getText().trim().length() != 0) {
-				try {
-					Class typeClass = Class.forName(selection[0].getText(1));
-					Object value = typeClass.getConstructor(Class.forName("java.lang.String")).newInstance(parameterValue.getText());
-					selection[0].setData(value);
-					selection[0].setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GREEN));
-				}
-				catch (Exception ex) {
-					errorLabel.setText("Error setting parameter value: could not be converted from String");
+	class AttributeTableLabelProvider implements ITableLabelProvider {
+
+		public Image getColumnImage(Object element, int columnIndex) {
+			return null;
+		}
+
+		public String getColumnText(Object element, int columnIndex) {
+			if (element instanceof ObjAttribute) {
+				ObjAttribute attribute = (ObjAttribute) element;
+				switch (columnIndex) {
+					case 0 : return attribute.getName();
+					case 1 : return attribute.getType();
+					case 2 : Operator operator = operatorMap.get(attribute.getName());
+							 return (operator == null ? new String("") : operator.toString());
+					case 3 : Object paramValue = paramMap.get(attribute.getName());
+							 return (paramValue == null ? new String("") : paramValue.toString());
 				}
 			}
-			else {
-				selection[0].setData(null);
-				selection[0].setBackground(attributeTable.getBackground());
-			}
+			return new String("");
+		}
+
+		public void addListener(ILabelProviderListener listener) {
+		}
+
+		public void dispose() {
+		}
+
+		public boolean isLabelProperty(Object element, String property) {
+			return false;
 		}
-	}
 
-	public void controlResized(ControlEvent e) {
-		if (e.getSource() == attributeTable) {
-			Point size;
-			
-			// handle the sizing of the table columns
-			size = attributeTable.getSize();
-			size.x -= attributeTable.getBorderWidth();
-			if (attributeTable.getVerticalBar() != null) {
-				size.x -= attributeTable.getVerticalBar().getSize().x;
-			} 
-
-			attributeName.setWidth((int) (size.x/2));
-			attributeType.setWidth((int) (size.x/2));
+		public void removeListener(ILabelProviderListener listener) {
 		}
+		
 	}
+	
+	class AttributeTableCellModifier implements ICellModifier {
+
+		public boolean canModify(Object element, String property) {
+			return (element instanceof ObjAttribute && (property.equals(COLUMN_NAMES[3]) || property.equals(COLUMN_NAMES[2])));
+		}
 
-	public void controlMoved(ControlEvent e) {
-	}
-
-	public String[] getParameterNames() {
-		ArrayList<String> names = new ArrayList<String>();
-		for (TableItem item : attributeTable.getItems()) {
-			if (item.getData() != null) {
-				names.add(item.getText(0));
+		public Object getValue(Object element, String property) {
+			if (element instanceof ObjAttribute) {
+				if (property.equals(COLUMN_NAMES[2])) {
+					Operator [] operators = Operator.values();
+					Operator operator = operatorMap.get(((ObjAttribute) element).getName());
+					int i = operators.length - 1;
+					while (i > 0 && !operators[i].equals(operator)) {
+						i--;
+					}
+					return new Integer(i);
+				}
+				if (property.equals(COLUMN_NAMES[3])) {
+					Object paramValue = paramMap.get(((ObjAttribute) element).getName());
+					return (paramValue == null ? new String("") : paramValue.toString());
+				}
 			}
+			return null;
 		}
-		return names.toArray(new String[names.size()]);
-	}
 
-	public Object[] getParameterValues() {
-		ArrayList<Object> values = new ArrayList<Object>();
-		for (TableItem item : attributeTable.getItems()) {
-			if (item.getData() != null) {
-				values.add(item.getData());
+		public void modify(Object element, String property, Object value) {
+			if (element instanceof TableItem) {
+				TableItem attribute = (TableItem) element;
+				if (property.equals(COLUMN_NAMES[2])) {
+					Operator [] operators = Operator.values();
+					Operator operator = operators[(Integer) value];
+					operatorMap.put(attribute.getText(0), operator);
+				}
+				else if (property.equals(COLUMN_NAMES[3])) {
+					if (value == null || (value instanceof String && ((String) value).length() == 0)) {
+						paramMap.remove(attribute.getText(0));
+					}
+					else {
+						try {
+							// try to use a constructor with a String parameter to translate to the correct type
+							Class typeClass = Class.forName(attribute.getText(1));
+							Object typedValue = typeClass.getConstructor(Class.forName("java.lang.String")).newInstance(value.toString());
+							paramMap.put(attribute.getText(0), typedValue);
+						}
+						catch (Exception ex) {
+							errorLabel.setText("Error setting parameter value: could not be converted from String");
+						}
+					}
+				}
+				attributeTable.refresh();
 			}
 		}
-		return values.toArray(new Object[values.size()]);
 	}
 }

Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectQueryWizard.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectQueryWizard.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectQueryWizard.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectQueryWizard.java Sun Aug  6 18:52:01 2006
@@ -15,29 +15,69 @@
  */
 package org.apache.cayenne.ropbrowser.wizards;
 
+import java.util.HashMap;
+
 import org.apache.cayenne.ropbrowser.model.AbstractObject;
 import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
 import org.objectstyle.cayenne.ObjectContext;
-import org.objectstyle.cayenne.query.NamedQuery;
+import org.objectstyle.cayenne.query.SelectQuery;
 
+/**
+ * A {@link Wizard} for use with {@link SelectQuery}. Can be used in
+ * two different modes: RETURN_PARAMS to get parameters for the query;
+ * RETURN_OBJECT to get a single object. Both use the parameters page to
+ * enter parameters, values specified for attributes to be used as the
+ * qualifier in a SelectQuery The latter has a second page for selecting
+ * the desired object from a list of results after the query has been run.
+ *  
+ * @author Marcel Gordon
+ */
 public class SelectQueryWizard extends Wizard {
 
-	private SelectParametersPage page1; // select a query and enter parameters
-	private SelectObjectPage page2; // select an object
-	
+	/**
+	 * Page 1 of the Wizard, the parameters page.
+	 */
+	private SelectParametersPage parametersPage; // select a query and enter parameters
+	/**
+	 * Page 2 of the Wizard (may be null), the object selection page.
+	 */
+	private SelectObjectPage objectPage; // select an object
+	
+	/**
+	 * The object that was selected if mode is RETURN_OBJECT
+	 */
 	private AbstractObject selectedObject;
 	
+	/**
+	 * The object context to use for discovering attributes
+	 */
 	private ObjectContext context;
+	/**
+	 * The name of the entity for which parameters are to be specified.
+	 */
 	private String entityName;
 	
+	/**
+	 * The mode of operation of the wizard.
+	 */
 	private int mode;
-	private Object[] paramValues;
-	private String[] paramNames;
 	
+	/**
+	 * Mode of operation in which the wizard returns an object which the user has selected.
+	 * Uses 2 pages.
+	 */
 	public static final int RETURN_OBJECT = 1;
+	/**
+	 * Mode of operation in which the wizard returns parameters which the user has selected.
+	 * Uses 1 page.
+	 */
 	public static final int RETURN_PARAMS = 2;
 	
+	/**
+	 * @param context the context to use to discover attributes and run the query
+	 * @param entityName the name of the entity for which parameters are to be specified or an object returned
+	 * @param mode the mode of operation of the dialog; see {@link #RETURN_OBJECT}, {@link #RETURN_PARAMS}
+	 */
 	public SelectQueryWizard(ObjectContext context, String entityName, int mode) {
 		this.context = context;
 		this.entityName = entityName;
@@ -49,66 +89,63 @@
 		if (mode == RETURN_OBJECT) {
 			return (selectedObject != null);
 		}
-		if (mode == RETURN_PARAMS) {
-			paramNames = page1.getParameterNames();
-			paramValues = page1.getParameterValues();
-			return true;
-		}
 		return true;
 	}
 	
+	@Override
 	public void addPages() {		
 		setWindowTitle("Select Object");
 		setHelpAvailable(false);
 		setNeedsProgressMonitor(false);
 		
-		page1 = new SelectParametersPage("Enter parameters", context, entityName);
-		addPage(page1);
+		parametersPage = new SelectParametersPage("Enter parameters", context, entityName);
+		addPage(parametersPage);
 		
 		if (mode == RETURN_OBJECT) {
-			page2 = new SelectObjectPage("Select an object", context, entityName);
-			addPage(page2);
+			objectPage = new SelectObjectPage("Select an object", context, entityName);
+			addPage(objectPage);
 		}
 	}
 
+	@Override
 	public boolean canFinish() {
 		if (mode == RETURN_OBJECT) {
 			return (selectedObject != null);
 		}
-		if (mode == RETURN_PARAMS) {
-			return true;
-		}
 		return true;
 	}
 	
+	/**
+	 * @return the object selected by the user if mode is RETURN_OBJECT
+	 */
 	public AbstractObject getSelectedObject() {
 		return selectedObject;
 	}
 	
-	public String[] getParameterNames() {
-		// the page has been disposed, need to go to copy stored on finish
-		if (mode == RETURN_PARAMS) {
-			return paramNames;
-		}
-		return page1.getParameterNames();
-	}
-	
-	public Object[] getParameterValues() {
-		// the page has been disposed, need to go to copy stored on finish
-		if (mode == RETURN_PARAMS) {
-			return paramValues;
-		}
-		return page1.getParameterValues();
-	}
-	
+	/**
+	 * @return name of the entity involved
+	 */
 	public String getEntityName() {
 		return entityName;
 	}
 
-	public SelectObjectPage getPage2() {
-		return page2;
+	/**
+	 * @return the page used to choose an object when mode is RETURN_OBJECT
+	 */
+	public SelectObjectPage getObjectPage() {
+		return objectPage;
+	}
+	
+	/**
+	 * @return the page used to input query parameters
+	 */
+	public SelectParametersPage getParametersPage() {
+		return parametersPage;
 	}
 
+	/**
+	 * @param data the object to selected by the user
+	 */
 	public void setSelectedObject(AbstractObject data) {
 		selectedObject = data;
 		getContainer().updateButtons();



Mime
View raw message