You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/08/07 03:52:04 UTC
svn commit: r429228 [1/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...
Author: aadamchik
Date: Sun Aug 6 18:52:01 2006
New Revision: 429228
URL: http://svn.apache.org/viewvc?rev=429228&view=rev
Log:
CAY-619
Added:
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_closed.gif (with props)
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_open.gif (with props)
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPPerspectiveFactory.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementRequest.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementLayoutEditPolicy.java
Removed:
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SingleDirectEditPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SingleSelectionPolicy.java
Modified:
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/plugin.xml
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ConnectionManager.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditor.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorContextMenuProvider.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorInput.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPBrowserPlugin.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/DeleteAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ExistingAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/HideAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/InsertAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RemoveAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RollbackAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/SetNameAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ToggleLayoutAction.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ContractRelationshipCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/DeleteObjectCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ElementSetConstraintCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectRequest.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExpandRelationshipCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/HideElementCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/NextObjectCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ObjectInsertCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/PopOutCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/RemoveObjectCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementCommand.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/figures/CollectionFigure.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/figures/CompartmentFigure.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/figures/ElementFigure.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/figures/SingleFigure.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/layout/DelegatingLayoutManager.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/layout/DirectedGraphLayoutVisitor.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/layout/GraphLayoutManager.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/layout/GraphXYLayout.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/AbstractObject.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/CollectionModelElement.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/Connection.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/ElementDiagram.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/MemberConnection.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/ModelElement.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/RelationshipConnection.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/SingleModelElement.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/auto/_Artist.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/auto/_Gallery.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/model/auto/_Painting.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/CollectionEditPart.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ConnectionEditPart.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementDiagramEditPart.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/ElementEditPart.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/parts/SingleEditPart.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionDirectEditPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/CollectionSelectionPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementEditPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/ElementXYLayoutEditPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/policies/SelectionHandlesEditPolicy.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/views/ControlPanelView.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectObjectPage.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectParametersPage.java
incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/wizards/SelectQueryWizard.java
Added: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_closed.gif
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_closed.gif?rev=429228&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_closed.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_open.gif
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_open.gif?rev=429228&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/icons/dropdown_open.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/plugin.xml?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/plugin.xml (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/plugin.xml Sun Aug 6 18:52:01 2006
@@ -22,5 +22,13 @@
id="org.apache.cayenne.ropbrowser.ObjectEditor"
name="Object Editor"/>
</extension>
+ <extension
+ point="org.eclipse.ui.perspectives">
+ <perspective
+ class="org.apache.cayenne.ropbrowser.ROPPerspectiveFactory"
+ icon="icons/sample.gif"
+ id="org.apache.cayenne.ropbrowser.ROPPerspectiveFactory"
+ name="ROP Browser"/>
+ </extension>
</plugin>
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ConnectionManager.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ConnectionManager.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ConnectionManager.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ConnectionManager.java Sun Aug 6 18:52:01 2006
@@ -17,17 +17,14 @@
package org.apache.cayenne.ropbrowser;
-import java.util.EventObject;
import java.util.Hashtable;
-import org.apache.cayenne.ropbrowser.model.AbstractObject;
+import org.eclipse.core.runtime.Status;
import org.objectstyle.cayenne.CayenneContext;
import org.objectstyle.cayenne.DataChannel;
import org.objectstyle.cayenne.ObjectContext;
-import org.objectstyle.cayenne.event.EventSubject;
import org.objectstyle.cayenne.graph.GraphEvent;
import org.objectstyle.cayenne.remote.ClientChannel;
-import org.objectstyle.cayenne.remote.ClientConnection;
import org.objectstyle.cayenne.remote.hessian.HessianConnection;
/**
@@ -38,8 +35,10 @@
*/
public class ConnectionManager {
- // TODO allow configuration of which attributes are displayed in elements
+ // TODO allow configuration of which attributes are displayed in elements?? and how??
+ // TODO allow configuration of how an object is converted to a String
+ /** Internal reference to the single instance of the class */
private static ConnectionManager _ref;
/** All connections made by the application */
private Hashtable<String, DataChannel> connections;
@@ -48,6 +47,9 @@
connections = new Hashtable<String, DataChannel>();
}
+ /**
+ * Get the single static instance of the class
+ */
public static ConnectionManager getInstance() {
if (_ref == null) {
_ref = new ConnectionManager();
@@ -69,18 +71,12 @@
}
else {
HessianConnection connection = new HessianConnection(address, null, null, "conference");
- try {
- channel = new ClientChannel(connection);
- connections.put(address, channel);
- } catch (Exception e) {
- // TODO log
- System.out.println("Error connecting to the server: " + e.getMessage());
- }
+ channel = new ClientChannel(connection);
+ connections.put(address, channel);
}
if (channel != null) {
// TODO XMPP notification of graph changes; DataChannel.* ?
- // TODO control panel XMPP option
channel.getEventManager().addListener(this, "handleXMPP", GraphEvent.class, DataChannel.GRAPH_CHANGED_SUBJECT);
channel.getEventManager().addListener(this, "handleXMPP", GraphEvent.class, DataChannel.GRAPH_FLUSHED_SUBJECT);
@@ -90,6 +86,9 @@
return null;
}
+ /**
+ * Deal with XMPP events
+ */
public void handleXMPP(GraphEvent event) {
System.out.println("XMPP : " + event.toString());
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditor.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditor.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditor.java Sun Aug 6 18:52:01 2006
@@ -49,11 +49,13 @@
*/
public class ObjectEditor extends GraphicalEditor {
+ // TODO move to Derby
+
/** ID of the Editor */
public static final String ID = "org.apache.cayenne.ropbrowser.ObjectEditor";
/** Root component of the data model */
private ElementDiagram elementDiagram;
-
+ /** Indicates whether the editor needs saving */
private boolean dirty;
public ObjectEditor() {
@@ -71,6 +73,7 @@
* Configure the graphical viewer before it receives contents.
* @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
*/
+ @Override
protected void configureGraphicalViewer() {
super.configureGraphicalViewer();
@@ -89,6 +92,7 @@
* Fires a property change event to inform the workbench that the editor has been modified.
* @see org.eclipse.gef.ui.parts.GraphicalEditor#commandStackChanged(java.util.EventObject)
*/
+ @Override
public void commandStackChanged(EventObject event) {
dirty = true;
firePropertyChange(IEditorPart.PROP_DIRTY);
@@ -98,12 +102,18 @@
/**
* Saves changes made in the editor back to the database.
*/
+ @Override
public void doSave(IProgressMonitor monitor) {
+ // TODO allow save view settings to a file??
elementDiagram.commitChanges();
dirty = false;
firePropertyChange(IEditorPart.PROP_DIRTY);
}
+ /**
+ * Returns whether there are changes to be saved
+ */
+ @Override
public boolean isDirty() {
return dirty;
}
@@ -111,24 +121,38 @@
/**
* Does nothing - no save as in this application.
*/
+ @Override
public void doSaveAs() {
}
/**
* Save as not allowed in this application.
*/
+ @Override
public boolean isSaveAsAllowed() {
return false;
}
+ /**
+ * Set the input for this editor. Only called when the editor is created
+ * initially.
+ */
+ @Override
protected void setInput(IEditorInput input) {
super.setInput(input);
+ // create the diagram using the context from the input
elementDiagram = new ElementDiagram(((ObjectEditorInput) input).getContext());
}
+ /**
+ * Create the actions available to the user via menus and toolbars.
+ */
+ @Override
protected void createActions() {
super.createActions();
+ // TODO enable menu and Ctrl + Z/Y undo/redo
+
IAction action = new HideAction(this);
getActionRegistry().registerAction(action);
getSelectionActions().add(action.getId());
@@ -160,15 +184,10 @@
getActionRegistry().registerAction(action);
}
+ /**
+ * @return the diagram that is the root of the model for this editor
+ */
public ElementDiagram getDiagram() {
return elementDiagram;
- }
-
- public void dispose() {
- super.dispose();
- // do it directly so as not to fire property change events
- if (isDirty()) {
- elementDiagram.getObjectContext().rollbackChanges();
- }
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorContextMenuProvider.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorContextMenuProvider.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorContextMenuProvider.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorContextMenuProvider.java Sun Aug 6 18:52:01 2006
@@ -59,6 +59,7 @@
* Creates context menu items for the editor.
* @see org.eclipse.gef.ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager)
*/
+ @Override
public void buildContextMenu(IMenuManager menu) {
// Add standard action groups to the menu
GEFActionConstants.addStandardActionGroups(menu);
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorInput.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorInput.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorInput.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ObjectEditorInput.java Sun Aug 6 18:52:01 2006
@@ -22,15 +22,21 @@
import org.objectstyle.cayenne.ObjectContext;
/**
- * Input for the ObjectEditor class, providing the context and
- * query needed to initialise the editor.
+ * Input for the ObjectEditor class, providing the information
+ * needed to initialise the editor.
*
* @author Marcel Gordon
*/
public class ObjectEditorInput implements IEditorInput {
+ /**
+ * The context for persistent objects in this editor
+ */
private ObjectContext context;
+ /**
+ * The address of the server from which the context comes
+ */
private String serverAddress;
public ObjectEditorInput(ObjectContext context, String address) {
@@ -47,7 +53,8 @@
}
/**
- * The name of the query contained in the Cayenne data map.
+ * The address of the server from which the context used by persistent
+ * objects in this editor comes.
*/
public String getName() {
return serverAddress;
@@ -57,6 +64,10 @@
return null;
}
+ /**
+ * @return the address of the server combined with the hashCode of the context,
+ * to be used as a tooltip.
+ */
public String getToolTipText() {
return serverAddress + " : " + context.hashCode();
}
@@ -67,15 +78,23 @@
/**
* Used to determine whether to open a new editor.
+ * @return always false so that a new editor is always opened.
*/
+ @Override
public boolean equals(Object o) {
return false;
}
+ /**
+ * @return the context used by persistent objects in this editor
+ */
public ObjectContext getContext() {
return context;
}
+ /**
+ * @return the address of the server from which the context comes
+ */
public String getServerAddress() {
return serverAddress;
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPBrowserPlugin.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPBrowserPlugin.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPBrowserPlugin.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPBrowserPlugin.java Sun Aug 6 18:52:01 2006
@@ -27,8 +27,17 @@
*/
public class ROPBrowserPlugin extends AbstractUIPlugin {
+ /**
+ * Plugin ID
+ */
+ public static final String ID = "ropbrowser";
+
//The shared instance.
private static ROPBrowserPlugin plugin;
+ /**
+ * A bolded font is stored here to ensure it is only created once
+ * and is disposed of when the plugin is stopped.
+ */
private Font boldFont;
public static final String IMG_DROP_OPEN = "dropdown_open.gif";
@@ -44,6 +53,7 @@
/**
* This method is called upon plug-in activation
*/
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
boldFont = new Font(null, "Arial", 9, SWT.BOLD);
@@ -54,6 +64,7 @@
/**
* This method is called when the plug-in is stopped
*/
+ @Override
public void stop(BundleContext context) throws Exception {
super.stop(context);
boldFont.dispose();
Added: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPPerspectiveFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPPerspectiveFactory.java?rev=429228&view=auto
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPPerspectiveFactory.java (added)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/ROPPerspectiveFactory.java Sun Aug 6 18:52:01 2006
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import org.apache.cayenne.ropbrowser.views.ControlPanelView;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class ROPPerspectiveFactory implements IPerspectiveFactory {
+
+ public void createInitialLayout(IPageLayout layout) {
+ layout.addView(ControlPanelView.ID, IPageLayout.RIGHT, 0.7f, IPageLayout.ID_EDITOR_AREA);
+ layout.addView(IPageLayout.ID_PROP_SHEET, IPageLayout.BOTTOM, 0.75f, ControlPanelView.ID);
+ layout.setEditorAreaVisible(true);
+ }
+}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/DeleteAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/DeleteAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/DeleteAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/DeleteAction.java Sun Aug 6 18:52:01 2006
@@ -26,11 +26,26 @@
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * An action which sends a DELETE_REQUEST to the selected part(s).
+ *
+ * @author Marcel Gordon
+ */
public class DeleteAction extends SelectionAction {
+ /**
+ * The request to be sent to selected parts
+ */
private Request request;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.DeleteAction";
+ /**
+ * The string used to identify the type of request.
+ * DELETE_REQUEST indicates that an object should be deleted from the database.
+ */
public static final String DELETE_REQUEST = "Delete";
public DeleteAction(IWorkbenchPart part) {
@@ -41,15 +56,13 @@
request = new Request(DELETE_REQUEST);
}
+ /**
+ * Test whether the action can be performed.
+ * @return true if the selection includes only {@link SingleEditPart} objects
+ * which are not storing null values.
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- execute(getCommand());
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
List parts = getSelectedObjects();
@@ -65,6 +78,14 @@
return true;
}
+ @Override
+ public void run() {
+ execute(getCommand());
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
CompoundCommand cc = new CompoundCommand();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ExistingAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ExistingAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ExistingAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ExistingAction.java Sun Aug 6 18:52:01 2006
@@ -20,32 +20,54 @@
import org.apache.cayenne.ropbrowser.commands.ExistingObjectRequest;
import org.apache.cayenne.ropbrowser.model.AbstractObject;
import org.apache.cayenne.ropbrowser.model.ModelElement;
-import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.apache.cayenne.ropbrowser.parts.CollectionEditPart;
import org.apache.cayenne.ropbrowser.parts.ElementEditPart;
import org.apache.cayenne.ropbrowser.parts.SingleEditPart;
import org.apache.cayenne.ropbrowser.wizards.SelectQueryWizard;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.jface.wizard.WizardDialog;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
import org.objectstyle.cayenne.ObjectContext;
+import org.objectstyle.cayenne.map.ObjEntity;
+/**
+ * An action which sends an {@link ExistingObjectRequest} to selected parts.
+ *
+ * @author Marcel Gordon
+ */
public class ExistingAction extends SelectionAction {
+ /**
+ * The request to be sent to selected parts.
+ */
private ExistingObjectRequest request;
+ /**
+ * The context of the persistent objects involved.
+ */
private ObjectContext context;
+ /**
+ * The name of the {@link ObjEntity} involved in the action.
+ * This corresponds to the name of the {@link ModelElement}s involved,
+ * as these are named after the type of {@link AbstractObject}s which they store.
+ * The name of the entity is used in querying the database for suitable
+ * objects to insert.
+ */
private String entityName;
+ /**
+ * The ID of the action.
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.ExistingAction";
+ /**
+ * @param context the context from which to load persistent objects
+ */
public ExistingAction(IWorkbenchPart part, ObjectContext context) {
super(part);
setId(ID);
@@ -54,21 +76,14 @@
this.context = context;
}
+ /**
+ * Test if the action is enabled.
+ * @return true if all selected parts are CollectionEditParts or SingleEditParts
+ * and they all have the same names (and hence store the same type of entity, allowing
+ * the insertion of the same object into all of them).
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- SelectQueryWizard wizard = new SelectQueryWizard(context, entityName, SelectQueryWizard.RETURN_OBJECT);
- WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
- dialog.create();
- if (dialog.open() == WizardDialog.OK) {
- request.setSelectedObject(wizard.getSelectedObject());
- execute(getCommand());
- }
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
List parts = getSelectedObjects();
@@ -79,6 +94,7 @@
}
// ensure that they all have the same entity name
+ // as a single object will be insert into all of them
ModelElement element = (ModelElement) ((ElementEditPart) o).getModel();
if (i == 0) {
entityName = element.getName();
@@ -90,6 +106,24 @@
return true;
}
+ /**
+ * Execute the action. This action runs a {@link SelectQueryWizard} to select
+ * the object for insertion before the command is executed.
+ */
+ @Override
+ public void run() {
+ SelectQueryWizard wizard = new SelectQueryWizard(context, entityName, SelectQueryWizard.RETURN_OBJECT);
+ WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard);
+ dialog.create();
+ if (dialog.open() == WizardDialog.OK) {
+ request.setSelectedObject(wizard.getSelectedObject());
+ execute(getCommand());
+ }
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
CompoundCommand cc = new CompoundCommand();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/HideAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/HideAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/HideAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/HideAction.java Sun Aug 6 18:52:01 2006
@@ -17,9 +17,7 @@
import java.util.List;
-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;
@@ -27,11 +25,26 @@
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * An action which sends a HIDE_REQUEST to selected parts.
+ *
+ * @author Marcel Gordon
+ */
public class HideAction extends SelectionAction {
+ /**
+ * The request to be sent to selected parts
+ */
private Request request;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.HideAction";
+ /**
+ * The string used to identify the type of request.
+ * HIDE_REQUEST indicates that the selected elements should be removed from the diagram.
+ */
public static final String HIDE_REQUEST = "Hide";
public HideAction(IWorkbenchPart part) {
@@ -41,15 +54,12 @@
request = new Request(HIDE_REQUEST);
}
+ /**
+ * Test whether the action can be performed.
+ * @return true if the selection includes only {@link ElementEditPart} objects.
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- execute(getCommand());
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
List parts = getSelectedObjects();
@@ -62,6 +72,14 @@
return true;
}
+ @Override
+ public void run() {
+ execute(getCommand());
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
CompoundCommand cc = new CompoundCommand();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/InsertAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/InsertAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/InsertAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/InsertAction.java Sun Aug 6 18:52:01 2006
@@ -27,29 +27,42 @@
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * Action which sends an INSERT_REQUEST to selected parts.
+ *
+ * @author Marcel Gordon
+ */
public class InsertAction extends SelectionAction {
+ /**
+ * The request to be sent to selected parts
+ */
private Request request;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.InsertAction";
+ /**
+ * The string used to identify the type of request.
+ * INSERT_REQUEST indicates that a new object should be inserted.
+ */
public static final String INSERT_REQUEST = "Insert";
public InsertAction(IWorkbenchPart part) {
super(part);
setId(ID);
- setText("Insert");
+ setText("Insert new object");
request = new Request(INSERT_REQUEST);
}
+ /**
+ * Tests whether the action is enabled.
+ * @return true if all selected elements are CollectionEditParts or
+ * SingleEditParts storing null values.
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- execute(getCommand());
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
List parts = getSelectedObjects();
@@ -65,6 +78,14 @@
return true;
}
+ @Override
+ public void run() {
+ execute(getCommand());
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
CompoundCommand cc = new CompoundCommand();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RemoveAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RemoveAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RemoveAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RemoveAction.java Sun Aug 6 18:52:01 2006
@@ -17,11 +17,8 @@
import java.util.List;
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
import org.apache.cayenne.ropbrowser.model.ModelElement;
-import org.apache.cayenne.ropbrowser.parts.CollectionEditPart;
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;
@@ -29,11 +26,26 @@
import org.eclipse.gef.ui.actions.SelectionAction;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * An action which sends a REMOVE_REQUEST to each selected part.
+ *
+ * @author Marcel Gordon
+ */
public class RemoveAction extends SelectionAction {
+ /**
+ * The request to be sent to selected parts
+ */
private Request request;
-
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.RemoveAction";
+ /**
+ * The string used to identify the type of request.
+ * REMOVE_REQUEST indicates that an object should be removed from the selected part
+ * but <b>not</b> deleted from the database.
+ */
public static final String REMOVE_REQUEST = "Remove";
public RemoveAction(IWorkbenchPart part) {
@@ -44,20 +56,21 @@
request = new Request(REMOVE_REQUEST);
}
+ /**
+ * Test whether the action can be performed.
+ * @return true if all of the selected parts are ElementEditParts
+ * and their contents are not null.
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- execute(getCommand());
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty())
return false;
List parts = getSelectedObjects();
for (int i=0; i<parts.size(); i++){
Object o = parts.get(i);
+ if (!(o instanceof ElementEditPart)) {
+ return false;
+ }
if (((ModelElement) ((ElementEditPart) o).getModel()).isNull()) {
return false;
}
@@ -65,6 +78,14 @@
return true;
}
+ @Override
+ public void run() {
+ execute(getCommand());
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
CompoundCommand cc = new CompoundCommand();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RollbackAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RollbackAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RollbackAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/RollbackAction.java Sun Aug 6 18:52:01 2006
@@ -18,19 +18,42 @@
import org.apache.cayenne.ropbrowser.ObjectEditor;
import org.eclipse.jface.action.Action;
-
-public class RollbackAction extends Action {
+/**
+ * Action used to rollback uncommitted changes in the editor.
+ * This action does not utilise a command.
+ *
+ * @author Marcel Gordon
+ */
+public class RollbackAction extends Action {
+ /**
+ * The editor to rollback changes in.
+ */
private ObjectEditor editor;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.RollbackAction";
+ /**
+ * @param editor the editor on which to rollback changes
+ */
public RollbackAction(ObjectEditor editor) {
this.editor = editor;
setId(ID);
setText("Rollback Changes");
}
+ /**
+ * Tests whether the action is enabled.
+ * @return true if the editor is dirty
+ */
+ public boolean calculateEnabled() {
+ return editor.isDirty();
+ }
+
+ @Override
public void run() {
editor.getDiagram().rollbackChanges();
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/SetNameAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/SetNameAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/SetNameAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/SetNameAction.java Sun Aug 6 18:52:01 2006
@@ -17,53 +17,78 @@
import java.util.List;
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
+import org.apache.cayenne.ropbrowser.commands.SetNameElementRequest;
import org.apache.cayenne.ropbrowser.model.ModelElement;
-import org.apache.cayenne.ropbrowser.parts.CollectionEditPart;
-import org.apache.cayenne.ropbrowser.parts.SingleEditPart;
+import org.apache.cayenne.ropbrowser.parts.ElementEditPart;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.ui.actions.SelectionAction;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
+/**
+ * Action used to set the name of the root element (see {@link ModelElement#isRoot()})
+ * where the name cannot be determined (for example where the initial query returns
+ * an empty set).
+ *
+ * @author Marcel Gordon
+ */
public class SetNameAction extends SelectionAction {
- private Request request;
-
+ /**
+ * The request to be sent to selected parts
+ */
+ private SetNameElementRequest request;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.SetNameAction";
- public static final String SET_NAME_REQUEST = "Set Name";
public SetNameAction(IWorkbenchPart part) {
super(part);
setId(ID);
setText("Set Name");
- request = new Request(SET_NAME_REQUEST);
+ request = new SetNameElementRequest();
}
+ /**
+ * Test whether the action can be performed.
+ * @return true if the element is the root of a query
+ */
+ @Override
protected boolean calculateEnabled() {
- return canPerformAction();
- }
-
- public void run() {
- execute(getCommand());
- }
-
- private boolean canPerformAction() {
if (getSelectedObjects().isEmpty() || getSelectedObjects().size() > 1)
return false;
List parts = getSelectedObjects();
Object o = parts.get(0);
- if (!(o instanceof CollectionEditPart)) {
+ if (!(o instanceof ElementEditPart)) {
return false;
}
- if (((CollectionModelElement) ((CollectionEditPart) o).getModel()).isRoot()) {
+ if (((ModelElement) ((ElementEditPart) o).getModel()).isRoot()) {
return true;
}
return false;
}
+ /**
+ * Uses a simple dialog to get the new name from the user
+ * before executing the command.
+ */
+ @Override
+ public void run() {
+ InputDialog iDialog = new InputDialog(Display.getCurrent().getActiveShell(), "Set Name", "Enter the name of the object", "", null);
+ int result = iDialog.open();
+ if (result == InputDialog.OK) {
+ String newName = iDialog.getValue();
+ request.setName(newName);
+ execute(getCommand());
+ }
+ }
+
+ /**
+ * Get commands from each selected part
+ */
private Command getCommand() {
List editparts = getSelectedObjects();
EditPart part = (EditPart)editparts.get(0);
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ToggleLayoutAction.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ToggleLayoutAction.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ToggleLayoutAction.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/actions/ToggleLayoutAction.java Sun Aug 6 18:52:01 2006
@@ -18,19 +18,34 @@
import org.apache.cayenne.ropbrowser.ObjectEditor;
import org.eclipse.jface.action.Action;
-
+/**
+ * Action used to toggle between automatic and manual layout modes.
+ * This action does not use a command.
+ *
+ * @author Marcel Gordon
+ */
public class ToggleLayoutAction extends Action {
+ /**
+ * The editor on which the layout should be toggled.
+ */
private ObjectEditor editor;
+ /**
+ * The ID of the action
+ */
public static final String ID = "org.apache.cayenne.ropbrowser.actions.ToggleLayoutAction";
+ /**
+ * @param editor the editor on which to toggle the layout
+ */
public ToggleLayoutAction(ObjectEditor editor) {
this.editor = editor;
setId(ID);
setText("Toggle Layout");
}
+ @Override
public void run() {
editor.getDiagram().toggleAutoLayout();
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ContractRelationshipCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ContractRelationshipCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ContractRelationshipCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ContractRelationshipCommand.java Sun Aug 6 18:52:01 2006
@@ -15,58 +15,65 @@
*/
package org.apache.cayenne.ropbrowser.commands;
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
-import org.apache.cayenne.ropbrowser.model.MemberConnection;
-import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
-import org.objectstyle.cayenne.map.Relationship;
+/**
+ * Command to contract a relationship, hiding an element.
+ *
+ * @author Marcel Gordon
+ */
public class ContractRelationshipCommand extends Command {
+ /**
+ * Source of the contracted connection
+ */
protected SingleModelElement source;
+ /**
+ * Connection representing the relationship to contract
+ */
protected RelationshipConnection conn;
- protected Command deleteCommand;
+ /**
+ * {@link HideElementCommand} used to hide the element which
+ * is the target of the relationship
+ */
+ protected Command hideCommand;
+ /**
+ * @param conn connection representing the relationship to contract
+ * @throws IllegalArgumentException if any parameter is null
+ */
public ContractRelationshipCommand(RelationshipConnection conn) {
this.conn = conn;
- this.deleteCommand = null;
+ this.hideCommand = null;
setLabel("contract relationship");
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
conn.disconnect();
if (!conn.getTarget().isConnectedToRoot()) {
- deleteCommand = new HideElementCommand(conn.getTarget());
- deleteCommand.execute();
+ hideCommand = new HideElementCommand(conn.getTarget());
+ hideCommand.execute();
}
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
conn.connect();
- if (deleteCommand != null) {
- deleteCommand.undo();
+ if (hideCommand != null) {
+ hideCommand.undo();
}
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/DeleteObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/DeleteObjectCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/DeleteObjectCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/DeleteObjectCommand.java Sun Aug 6 18:52:01 2006
@@ -15,22 +15,24 @@
*/
package org.apache.cayenne.ropbrowser.commands;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.cayenne.ropbrowser.model.Connection;
import org.apache.cayenne.ropbrowser.model.ModelElement;
+import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
+/**
+ * Command to delete an object from the database. This command
+ * is applied to a {@link SingleModelElement}, deleting the object
+ * which it contains.
+ *
+ * @author Marcel Gordon
+ */
public class DeleteObjectCommand extends Command {
- /** ModelElement to remove. */
+ /** element from which to delete the current object */
private final ModelElement element;
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
+ * @param element element from which to delete the current object
* @throws IllegalArgumentException if any parameter is null
*/
public DeleteObjectCommand(ModelElement element) {
@@ -41,18 +43,18 @@
this.element = element;
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return false;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
+ public boolean canExecute() {
+ return element.isNull();
+ }
+
+ @Override
public void execute() {
- //element.getDiagram().removeObject(element.getCurrentObject());
element.deleteCurrentObject();
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ElementSetConstraintCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ElementSetConstraintCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ElementSetConstraintCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ElementSetConstraintCommand.java Sun Aug 6 18:52:01 2006
@@ -18,21 +18,33 @@
import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
/**
- * Command for moving or resizing an element in the editor.
+ * Command for moving an element in the editor.
*
* @author Marcel Gordon
*/
public class ElementSetConstraintCommand extends Command {
+ /**
+ * The element to move
+ */
private ModelElement element;
+ /**
+ * The old bounds of the element
+ */
private Rectangle oldBounds;
+ /**
+ * The new bounds of the element
+ */
private Rectangle newBounds;
+ /**
+ * @param element element to move
+ * @param oldBounds the old bounds of the element
+ * @param newBounds the new bounds of the element
+ */
public ElementSetConstraintCommand(ModelElement element, Rectangle oldBounds, Rectangle newBounds)
{
super();
@@ -42,15 +54,18 @@
setLabel("move");
}
+ @Override
public void execute()
{
redo();
}
+ @Override
public void redo() {
element.modifyBounds(newBounds);
}
+ @Override
public void undo()
{
element.modifyBounds(oldBounds);
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectCommand.java Sun Aug 6 18:52:01 2006
@@ -15,6 +15,9 @@
*/
package org.apache.cayenne.ropbrowser.commands;
+import java.util.ArrayList;
+import java.util.Collection;
+
import org.apache.cayenne.ropbrowser.model.AbstractObject;
import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
import org.apache.cayenne.ropbrowser.model.Connection;
@@ -22,83 +25,140 @@
import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
-import org.objectstyle.cayenne.map.ObjEntity;
+/**
+ * Command used to insert an existing object into a {@link ModelElement}.
+ *
+ * @author Marcel Gordon
+ */
public class ExistingObjectCommand extends Command {
/** ModelElement to insert a record into. */
private final ModelElement element;
+ /** the object inserted */
private final AbstractObject object;
+ /** the object replaced (may be null) */
+ private AbstractObject replacedObject;
+
+ /** the existing element that replaced {@link #element} (may be null) */
+ private SingleModelElement replacingElement;
+
+ /** target connections of the replaced element */
+ private ArrayList<RelationshipConnection> replacedConnections;
+
+ /** target connections which replaced {@link #replacedConnections} */
+ private ArrayList<RelationshipConnection> replacingConnections;
+
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
+ * @param element element into which to insert the object
+ * @param object object to insert
* @throws IllegalArgumentException if any parameter is null
*/
public ExistingObjectCommand(ModelElement element, AbstractObject object) {
if (element == null) {
throw new IllegalArgumentException();
}
- setLabel("existing object");
+ setLabel("insert existing object");
this.element = element;
this.object = object;
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
- return false;
+ return !(element instanceof CollectionModelElement);
}
+ @Override
public boolean canExecute() {
return !element.contains(object);
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
+ redo();
+ }
+
+ @Override
+ public void redo() {
+ replacingConnections = new ArrayList<RelationshipConnection>();
+ replacedConnections = new ArrayList<RelationshipConnection>();
+
if (element instanceof CollectionModelElement) {
element.addObject(object);
+ ((CollectionModelElement) element).setCurrentObject(object);
}
else if (element instanceof SingleModelElement) {
- if (element.isNull()) {
- ModelElement existing = element.getDiagram().getSingleElementForObject(object);
- if (existing == null) { // no existing element - just set this one up
- element.addObject(object);
- }
- else { // a single model element with this object already exists; link to it
- for (Connection conn : element.getTargetConnections()) {
- if (conn instanceof RelationshipConnection) {
- RelationshipConnection relConn = (RelationshipConnection) conn;
- relConn.getSource().getCurrentObject().setRelationship(relConn.getRelationship(), element.getCurrentObject(), object);
- relConn.disconnect();
- RelationshipConnection newConn = new RelationshipConnection(relConn.getSource(), existing, relConn.getRelationship());
- newConn.connect();
- }
+ replacingElement = element.getDiagram().getSingleElementForObject(object);
+ replacedObject = element.getCurrentObject();
+ if (replacingElement == null) { // no existing element - just set this one up
+ element.addObject(object);
+
+ // contract relationships because they may no longer be accurate
+ for (Connection conn : element.getSourceConnections()) {
+ if (conn instanceof RelationshipConnection) {
+ Command conCommand = new ContractRelationshipCommand((RelationshipConnection) conn);
+ conCommand.execute();
}
- HideElementCommand recCommand = new HideElementCommand(element);
- recCommand.execute();
}
}
- else {
+ else { // a single model element with this object already exists; link to it
for (Connection conn : element.getTargetConnections()) {
if (conn instanceof RelationshipConnection) {
RelationshipConnection relConn = (RelationshipConnection) conn;
relConn.getSource().getCurrentObject().setRelationship(relConn.getRelationship(), element.getCurrentObject(), object);
+ relConn.disconnect();
+ RelationshipConnection newConn = new RelationshipConnection(relConn.getSource(), replacingElement, relConn.getRelationship());
+ newConn.connect();
+ replacedConnections.add(relConn);
+ replacingConnections.add(newConn);
}
}
- element.setObject(object);
- element.getDiagram().createMemberConnections(element);
- for (Connection conn : element.getSourceConnections()) {
+
+ // hide the old element - it is no longer needed
+ HideElementCommand recCommand = new HideElementCommand(element);
+ recCommand.execute();
+
+ // contract relationships because they may no longer be accurate
+ for (Connection conn : replacingElement.getSourceConnections()) {
if (conn instanceof RelationshipConnection) { // this should always be true
- Command recCommand = new ContractRelationshipCommand((RelationshipConnection) conn);
- recCommand.execute();
+ Command conCommand = new ContractRelationshipCommand((RelationshipConnection) conn);
+ conCommand.execute();
}
}
+ }
+
+ }
+ }
+
+ @Override
+ public void undo() {
+ /*
+ * Insert into CME cannot be undone at present.
+ * Although the object is removed from the CME
+ * into which it was inserted, it is not added
+ * into any CME from which it was effectively
+ * removed, and can end up with a null relationship
+ * where it did not have one previously.
+ *
+ if (element instanceof CollectionModelElement) {
+ element.removeObject(object);
+ }
+ */
+ if (element instanceof SingleModelElement) {
+ if (replacingElement == null) { // the element wasn't replaced
+ element.addObject(replacedObject);
+ }
+ else { // the element was replaced with an existing element
+ element.getDiagram().addElement(element);
+ for (RelationshipConnection newConn : replacingConnections) {
+ newConn.getSource().getCurrentObject().setRelationship(newConn.getRelationship(), replacingElement.getCurrentObject(), replacedObject);
+ newConn.disconnect();
+ }
+ for (RelationshipConnection relConn : replacedConnections) {
+ relConn.connect();
+ }
}
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectRequest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectRequest.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectRequest.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExistingObjectRequest.java Sun Aug 6 18:52:01 2006
@@ -18,8 +18,16 @@
import org.apache.cayenne.ropbrowser.model.AbstractObject;
import org.eclipse.gef.Request;
+/**
+ * Request used to insert an existing object into an element.
+ *
+ * @author Marcel Gordon
+ */
public class ExistingObjectRequest extends Request {
+ /**
+ * The object to insert
+ */
private AbstractObject selectedObject;
public static final String EXISTING_REQUEST = "Existing Object";
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExpandRelationshipCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExpandRelationshipCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExpandRelationshipCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ExpandRelationshipCommand.java Sun Aug 6 18:52:01 2006
@@ -16,45 +16,63 @@
package org.apache.cayenne.ropbrowser.commands;
import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
-import org.apache.cayenne.ropbrowser.model.MemberConnection;
import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
import org.objectstyle.cayenne.map.Relationship;
+/**
+ * Command to expand a relationship from a {@link SingleModelElement},
+ * displaying the objects related through that relationship in a separate element.
+ *
+ * @author Marcel Gordon
+ */
public class ExpandRelationshipCommand extends Command {
+ /**
+ * The relationship to expand
+ */
protected Relationship relationship;
+ /**
+ * The source element
+ */
protected SingleModelElement source;
+ /**
+ * The relationship connection created as a result of the expansion
+ */
protected RelationshipConnection conn;
- public ExpandRelationshipCommand(SingleModelElement source, Relationship relationship) {
+ /**
+ * @param source the source of the relationship
+ * @param relationship the relationship to expand
+ * @throws IllegalArgumentException if any parameter is null
+ */
+ public ExpandRelationshipCommand(SingleModelElement source, Relationship relationship) throws IllegalArgumentException {
+ if (source == null || relationship == null) {
+ throw new IllegalArgumentException();
+ }
this.relationship = relationship;
this.source = source;
setLabel("expand relationship");
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
Object value = source.getCurrentObject().followRelationship(relationship);
+ // create the element and set its contents
+
ModelElement newElement;
if (relationship.isToMany()) {
@@ -65,9 +83,9 @@
}
newElement.setObject(value);
-
+
if (source.getDiagram().addElement(newElement)) {
- // add the element as a new element; check for member connections
+ // no such element exists; the new element has been added into the diagram
conn = new RelationshipConnection(source, newElement, relationship);
}
else {
@@ -77,9 +95,7 @@
conn.connect();
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
Command contractCommand = new ContractRelationshipCommand(conn);
contractCommand.execute();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/HideElementCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/HideElementCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/HideElementCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/HideElementCommand.java Sun Aug 6 18:52:01 2006
@@ -17,36 +17,42 @@
package org.apache.cayenne.ropbrowser.commands;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
import org.apache.cayenne.ropbrowser.model.Connection;
-import org.apache.cayenne.ropbrowser.model.MemberConnection;
import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
-import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
/**
- * Command for deleting an element from the ObjectDiagram.
+ * Command for removing an element from the ObjectDiagram. This
+ * <b>will not</b> alter the database; it simply removes the visual
+ * element from the diagram.
*
* @author Marcel Gordon
*/
public class HideElementCommand extends Command {
- /** ModelElement to remove. */
+ /** ModelElement to hide */
private final ModelElement element;
+ /**
+ * Commands used to hide connected elements which
+ * would otherwise not be connected to a root element.
+ */
private ArrayList<Command> subcommands;
+ /**
+ * Source connections of the hidden element.
+ */
private List<Connection> sourceConnections;
+ /**
+ * Target connections of the hidden element.
+ */
private List<Connection> targetConnections;
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
+ * @param element the element to hide
* @throws IllegalArgumentException if any parameter is null
*/
public HideElementCommand(ModelElement element) {
@@ -55,51 +61,55 @@
}
setLabel("hide element");
this.element = element;
- subcommands = new ArrayList<Command>();
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
sourceConnections = element.getSourceConnections();
targetConnections = element.getTargetConnections();
redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
+ subcommands = new ArrayList<Command>();
+
+ // disconnect all connections to and from this element
for (Connection conn : element.getTargetConnections()) {
conn.disconnect();
}
+
for (Connection conn : element.getSourceConnections()) {
conn.disconnect();
+
+ // hide any elements which are no longer connected to the root
if (!conn.getTarget().isConnectedToRoot()) {
Command recCommand = new HideElementCommand(conn.getTarget());
subcommands.add(recCommand);
recCommand.execute();
}
+
}
+
+ // remove the element from the diagram
+
element.getDiagram().removeElement(element);
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
+ // restore all the elements which were hidden by subcommands
for (Command command : subcommands) {
command.undo();
- }
+ }
+
+ // reconnect the hidden elements connections
for (Connection conn : sourceConnections) {
if (conn instanceof RelationshipConnection) {
conn.connect();
@@ -110,6 +120,8 @@
conn.connect();
}
}
+
+ // add the element back into the diagram
element.getDiagram().addElement(element);
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/NextObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/NextObjectCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/NextObjectCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/NextObjectCommand.java Sun Aug 6 18:52:01 2006
@@ -18,39 +18,40 @@
import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
import org.eclipse.gef.commands.Command;
+/**
+ * Command to display the next object in a {@link CollectionModelElement}
+ *
+ * @author Marcel Gordon
+ */
public class NextObjectCommand extends Command {
private CollectionModelElement element;
+ /**
+ * @param element the element in which to scroll to the next object
+ * @throws IllegalArgumentException if any parameter is null
+ */
public NextObjectCommand(CollectionModelElement element) {
this.element = element;
setLabel("next object");
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
element.next();
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
element.previous();
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ObjectInsertCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ObjectInsertCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ObjectInsertCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/ObjectInsertCommand.java Sun Aug 6 18:52:01 2006
@@ -17,22 +17,24 @@
import org.apache.cayenne.ropbrowser.model.AbstractObject;
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.eclipse.gef.commands.Command;
import org.objectstyle.cayenne.map.ObjEntity;
+/**
+ * Command to insert a new object into an element
+ *
+ * @author Marcel Gordon
+ */
public class ObjectInsertCommand extends Command {
- /** ModelElement to insert a record into. */
+ /** ModelElement to insert an object into. */
private final ModelElement element;
+ /** The inserted object */
+ private AbstractObject object;
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
+ * @param element the element into which the object should be inserted
* @throws IllegalArgumentException if any parameter is null
*/
public ObjectInsertCommand(ModelElement element) {
@@ -43,20 +45,30 @@
this.element = element;
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
- return false;
+ return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
- public void execute() {
+ @Override
+ public void redo() {
ObjEntity entity = element.getDiagram().getObjectContext().getEntityResolver().getObjEntity(element.getName());
Class entityClass = entity.getJavaClass();
- AbstractObject object = (AbstractObject) element.getDiagram().getObjectContext().newObject(entityClass);
+ object = (AbstractObject) element.getDiagram().getObjectContext().newObject(entityClass);
element.addObject(object);
+ if (element instanceof CollectionModelElement) {
+ ((CollectionModelElement) element).setCurrentObject(object);
+ }
+ }
+
+ @Override
+ public void undo() {
+ element.removeObject(object);
+ object.getObjectContext().deleteObject(object);
+ }
+
+ @Override
+ public void execute() {
+ redo();
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/PopOutCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/PopOutCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/PopOutCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/PopOutCommand.java Sun Aug 6 18:52:01 2006
@@ -16,51 +16,57 @@
package org.apache.cayenne.ropbrowser.commands;
import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
-import org.apache.cayenne.ropbrowser.model.MemberConnection;
-import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
+/**
+ * Command to pop the current object out of a {@link CollectionModelElement} into a {@link SingleModelElement}
+ *
+ * @author Marcel Gordon
+ */
public class PopOutCommand extends Command {
+ /**
+ * The element from which to pop out the current object
+ */
private CollectionModelElement element;
+ /**
+ * The element which was created by the pop out
+ */
private SingleModelElement newElement;
+ /**
+ * @param element the element from which to pop out the current object
+ * @throws IllegalArgumentException if any parameter is null
+ */
public PopOutCommand(CollectionModelElement element) {
this.element = element;
setLabel("pop out");
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
+ @Override
public boolean canExecute() {
return !element.isNull();
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
newElement = new SingleModelElement(element.getName());
newElement.setObject(element.getCurrentObject());
element.getDiagram().addElement(newElement);
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
Command deleteCommand = new HideElementCommand(newElement);
deleteCommand.execute();
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/RemoveObjectCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/RemoveObjectCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/RemoveObjectCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/RemoveObjectCommand.java Sun Aug 6 18:52:01 2006
@@ -15,22 +15,25 @@
*/
package org.apache.cayenne.ropbrowser.commands;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.cayenne.ropbrowser.model.Connection;
+import org.apache.cayenne.ropbrowser.model.AbstractObject;
import org.apache.cayenne.ropbrowser.model.ModelElement;
import org.eclipse.gef.commands.Command;
+/**
+ * Command to remove an object from an element, <b>without</b> deleting
+ * it from the database.
+ *
+ * @author Marcel Gordon
+ */
public class RemoveObjectCommand extends Command {
/** ModelElement to remove. */
private final ModelElement element;
+ /** The object which was removed */
+ private AbstractObject removed;
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
+ * @param element the element to remove
* @throws IllegalArgumentException if any parameter is null
*/
public RemoveObjectCommand(ModelElement element) {
@@ -41,17 +44,24 @@
this.element = element;
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
- return false;
+ return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
- element.removeObject(element.getCurrentObject());
+ redo();
+ }
+
+ @Override
+ public void redo() {
+ removed = element.getCurrentObject();
+ element.removeObject(removed);
+ }
+
+ @Override
+ public void undo() {
+ element.addObject(removed);
}
}
Modified: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementCommand.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementCommand.java?rev=429228&r1=429227&r2=429228&view=diff
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementCommand.java (original)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementCommand.java Sun Aug 6 18:52:01 2006
@@ -16,77 +16,59 @@
*/
package org.apache.cayenne.ropbrowser.commands;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.cayenne.ropbrowser.model.CollectionModelElement;
-import org.apache.cayenne.ropbrowser.model.Connection;
-import org.apache.cayenne.ropbrowser.model.MemberConnection;
import org.apache.cayenne.ropbrowser.model.ModelElement;
-import org.apache.cayenne.ropbrowser.model.RelationshipConnection;
-import org.apache.cayenne.ropbrowser.model.SingleModelElement;
import org.eclipse.gef.commands.Command;
-import org.eclipse.jface.dialogs.InputDialog;
-import org.eclipse.swt.widgets.Display;
/**
- * Command for deleting an element from the ObjectDiagram.
+ * Command for setting the name of an element.
*
* @author Marcel Gordon
*/
public class SetNameElementCommand extends Command {
- /** ModelElement to remove. */
+ /** ModelElement to rename */
private final ModelElement element;
+ /**
+ * The name to be given to the element
+ */
private String newName;
+ /**
+ * The name of the element before the execution of this command
+ */
private String oldName;
/**
- * Create a command that will remove the ModelElement from its parent ElementDiagram.
- * @param parent the ElementDiagram containing the child
- * @param child the ModelElement to remove
- * @throws IllegalArgumentException if any parameter is null
+ * @param element the element whose name is to be set
+ * @param name the new name of the element
+ * @throws IllegalArgumentException if element is null
*/
- public SetNameElementCommand(ModelElement element) {
+ public SetNameElementCommand(ModelElement element, String name) {
if (element == null) {
throw new IllegalArgumentException();
}
setLabel("set name");
this.element = element;
+ this.newName = name;
}
- /**
- * @see org.eclipse.gef.commands.Command#canUndo()
- */
+ @Override
public boolean canUndo() {
return true;
}
- /**
- * @see org.eclipse.gef.commands.Command#execute()
- */
+ @Override
public void execute() {
oldName = element.getName();
- InputDialog iDialog = new InputDialog(Display.getCurrent().getActiveShell(), "Set Name", "Enter the name of the object", "", null);
- int result = iDialog.open();
- if (result == InputDialog.OK) {
- newName = iDialog.getValue();
- redo();
- }
+ redo();
}
- /**
- * @see org.eclipse.gef.commands.Command#redo()
- */
+ @Override
public void redo() {
element.setName(newName);
}
- /**
- * @see org.eclipse.gef.commands.Command#undo()
- */
+ @Override
public void undo() {
element.setName(oldName);
}
Added: incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementRequest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementRequest.java?rev=429228&view=auto
==============================================================================
--- incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementRequest.java (added)
+++ incubator/cayenne/soc/trunk/cayenne-rop/rop-browser/src/org/apache/cayenne/ropbrowser/commands/SetNameElementRequest.java Sun Aug 6 18:52:01 2006
@@ -0,0 +1,45 @@
+/*
+ * 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.commands;
+
+import org.eclipse.gef.Request;
+
+/**
+ * Request used to set the name of the element.
+ *
+ * @author Marcel Gordon
+ */
+public class SetNameElementRequest extends Request {
+
+ /**
+ * The new name of the element.
+ */
+ private String name;
+
+ public static final String SET_NAME_REQUEST = "Set Name";
+
+ public SetNameElementRequest() {
+ super(SET_NAME_REQUEST);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}