cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkazimirc...@apache.org
Subject svn commit: r1141870 - in /cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: action/ dialog/query/
Date Fri, 01 Jul 2011 08:37:59 GMT
Author: dkazimirchyk
Date: Fri Jul  1 08:37:58 2011
New Revision: 1141870

URL: http://svn.apache.org/viewvc?rev=1141870&view=rev
Log:
CAY-1461 CayenneModeler: remove ScopeMVC dependency - ObjRelationshipInfoDialog

patches by Rostislav with some edits
removed scopemvc dependencies from QueryType dialog

Added:
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryType.java
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeView.java
Removed:
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeController.java
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeDialog.java
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeModel.java
Modified:
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateQueryAction.java
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateQueryAction.java?rev=1141870&r1=1141869&r2=1141870&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateQueryAction.java
(original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateQueryAction.java
Fri Jul  1 08:37:58 2011
@@ -27,7 +27,7 @@ import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.dialog.query.QueryTypeController;
+import org.apache.cayenne.modeler.dialog.query.QueryType;
 import org.apache.cayenne.modeler.event.QueryDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.query.Query;
@@ -59,7 +59,7 @@ public class CreateQueryAction extends C
     }
 
     protected void createQuery() {
-        new QueryTypeController(getProjectController()).startup();
+        new QueryType(getProjectController(),getProjectController().getCurrentDataMap()).startupAction();
     }
     
     public void createQuery(DataChannelDescriptor domain, DataMap dataMap, Query query) {

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java?rev=1141870&r1=1141869&r2=1141870&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
(original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/PasteAction.java
Fri Jul  1 08:37:58 2011
@@ -48,7 +48,7 @@ import org.apache.cayenne.map.ProcedureP
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
-import org.apache.cayenne.modeler.dialog.query.QueryTypeController;
+import org.apache.cayenne.modeler.dialog.query.QueryType;
 import org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit;
 import org.apache.cayenne.modeler.undo.PasteUndoableEdit;
 import org.apache.cayenne.modeler.util.CayenneAction;
@@ -328,7 +328,7 @@ public class PasteAction extends Cayenne
                 query.setDataMap(dataMap);
 
                 dataMap.addQuery(query);
-                QueryTypeController.fireQueryEvent(this, mediator, dataMap, query);
+                QueryType.fireQueryEvent(this, mediator, dataMap, query);
             }
             else if (content instanceof Procedure) {
                 // paste Procedure to DataMap

Added: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryType.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryType.java?rev=1141870&view=auto
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryType.java
(added)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryType.java
Fri Jul  1 08:37:58 2011
@@ -0,0 +1,200 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.modeler.dialog.query;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.WindowConstants;
+
+import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.configuration.event.QueryEvent;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.event.MapEvent;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.QueryDisplayEvent;
+import org.apache.cayenne.modeler.undo.CreateQueryUndoableEdit;
+import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.query.AbstractQuery;
+import org.apache.cayenne.query.EJBQLQuery;
+import org.apache.cayenne.query.ProcedureQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.util.NamedObjectFactory;
+
+
+public class QueryType extends CayenneController{
+
+    protected ProjectController mediator;
+    protected DataMap dataMap;
+    protected DataChannelDescriptor domain;
+    protected Query query;
+    
+    // query prototypes...
+    protected AbstractQuery objectSelectQuery;
+    protected AbstractQuery rawSQLQuery;
+    protected AbstractQuery procedureQuery;
+    protected EJBQLQuery ejbqlQuery;
+    protected QueryTypeView view;
+    protected Query selectedQuery;
+    
+    public QueryType(ProjectController mediator,DataMap root) {
+        super(mediator);
+        
+        // create query prototypes:
+        objectSelectQuery = new SelectQuery();
+        procedureQuery = new ProcedureQuery();
+        view = new QueryTypeView();
+        initController();
+        SQLTemplate rawSQLQuery = new SQLTemplate();
+        rawSQLQuery.setRoot(root);
+        rawSQLQuery.setFetchingDataRows(true);
+        this.rawSQLQuery = rawSQLQuery;
+        
+        ejbqlQuery = new EJBQLQuery();
+        // by default use object query...
+        selectedQuery = objectSelectQuery;
+        this.mediator = mediator;
+        this.dataMap = mediator.getCurrentDataMap();
+        this.domain = (DataChannelDescriptor)mediator.getProject().getRootNode();
+    }
+
+    @Override
+    public Component getView() {
+        return view;
+    } 
+    
+    private void initController() {
+        view.getCancelButton().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                view.dispose();
+            }
+        });
+        view.getSaveButton().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                createQuery();
+            }
+        });
+        view.getObjectSelect().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                 setObjectSelectQuery();
+            }
+        });
+        view.getSqlSelect().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+               setRawSQLQuery();
+            }
+        });
+        view.getProcedureSelect().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                setProcedureQuery();
+            }
+        });
+        view.getEjbqlSelect().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                setEjbqlQuery();
+            }
+        });
+    }
+    
+    public void startupAction() {
+        view.pack();
+        view.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+        view.setModal(true);
+        makeCloseableOnEscape();
+        centerView();
+        view.setVisible(true);
+    }
+    
+    /**
+     * Action method that creates a query for the specified query type.
+     */
+    public void createQuery() {
+        Query query =getSelectedQuery();
+        if (query == null) {
+            return;
+        }
+
+        // update query...
+        String queryName = NamedObjectFactory.createName(Query.class, dataMap);
+        if (query instanceof EJBQLQuery) {
+            ((EJBQLQuery) query).setName(queryName);
+            ((EJBQLQuery) query).setDataMap(dataMap);
+        } else {
+            ((AbstractQuery) query).setName(queryName);
+            ((AbstractQuery) query).setDataMap(dataMap);
+        }
+        
+        dataMap.addQuery(query);
+
+        mediator.getApplication().getUndoManager().addEdit(
+                new CreateQueryUndoableEdit(domain, dataMap, query));
+
+        // notify listeners
+        fireQueryEvent(this, mediator,dataMap, query);
+        view.dispose();
+    }
+
+    /**
+     * Fires events when a query was added
+     */
+    public static void fireQueryEvent(Object src, ProjectController mediator,
+            DataMap dataMap, Query query) {
+        mediator.fireQueryEvent(new QueryEvent(src, query, MapEvent.ADD,
+                dataMap));
+        mediator.fireQueryDisplayEvent(new QueryDisplayEvent(src, query,
+                dataMap, (DataChannelDescriptor)mediator.getProject().getRootNode()));
+    }
+    
+    public Query getSelectedQuery() {
+        return selectedQuery;
+    }
+
+    public void setSelectedQuery(AbstractQuery selectedQuery) {
+        this.selectedQuery = selectedQuery;
+    }
+
+    public void setObjectSelectQuery() {
+        selectedQuery = objectSelectQuery;   
+    }
+    
+    public void setRawSQLQuery() {
+        selectedQuery = rawSQLQuery;
+    }
+
+    public boolean isProcedureQuery() {
+        return selectedQuery == procedureQuery;
+    }
+
+    public void setProcedureQuery() {
+        selectedQuery = procedureQuery;   
+    }
+       
+    public void setEjbqlQuery() {
+        selectedQuery = ejbqlQuery;
+    }
+}

Added: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeView.java?rev=1141870&view=auto
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeView.java
(added)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/query/QueryTypeView.java
Fri Jul  1 08:37:58 2011
@@ -0,0 +1,120 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.modeler.dialog.query;
+
+import java.awt.BorderLayout;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JRadioButton;
+
+import org.apache.cayenne.modeler.util.PanelFactory;
+
+import com.jgoodies.forms.builder.PanelBuilder;
+import com.jgoodies.forms.layout.CellConstraints;
+import com.jgoodies.forms.layout.FormLayout;
+
+public class QueryTypeView extends JDialog {
+    
+    protected ButtonGroup buttonGroup;
+    protected JRadioButton objectSelect;
+    protected JRadioButton sqlSelect;
+    protected JRadioButton procedureSelect;
+    protected JRadioButton ejbqlSelect;
+    protected JButton createButton;
+    protected JButton cancelButton;
+    
+    public QueryTypeView() {
+        initView();
+    }
+    
+    private void initView() {
+        
+        // create widgets
+        ButtonGroup buttonGroup = new ButtonGroup();
+        objectSelect = new JRadioButton("Object Select Query");
+        sqlSelect = new JRadioButton("Raw SQL");
+        procedureSelect = new JRadioButton("Stored Procedure Query");
+        ejbqlSelect = new JRadioButton("EJBQL Query");
+        objectSelect.setSelected(true);
+        buttonGroup.add(objectSelect);
+        buttonGroup.add(sqlSelect);
+        buttonGroup.add(procedureSelect);
+        buttonGroup.add(ejbqlSelect);
+
+        createButton = new JButton("Create"); 
+        createButton.setEnabled(true);
+
+        cancelButton = new JButton("Cancel");
+        cancelButton.setEnabled(true);
+ 
+        // assemble
+        CellConstraints cc = new CellConstraints();
+        FormLayout layout = new FormLayout(
+                "left:max(180dlu;pref)",
+                "p, 4dlu, p, 4dlu, p, 4dlu, p, 4dlu");
+        PanelBuilder builder = new PanelBuilder(layout);
+        builder.setDefaultDialogBorder();
+
+        builder.add(objectSelect, cc.xy(1, 1));
+        builder.add(sqlSelect, cc.xy(1, 3));
+        builder.add(procedureSelect, cc.xy(1, 5));
+        builder.add(ejbqlSelect, cc.xy(1, 7));
+
+        setLayout(new BorderLayout());
+        add(builder.getPanel(), BorderLayout.CENTER);
+
+        add(PanelFactory.createButtonPanel(new JButton[] {
+                createButton, cancelButton
+        }), BorderLayout.SOUTH);
+
+        setTitle("Select New Query Type");
+    }
+    
+    public JButton getSaveButton()
+    {
+        return createButton;
+    }
+    
+    public JButton getCancelButton()
+    {
+        return cancelButton;
+    }
+    
+    public JRadioButton getObjectSelect()
+    {
+        return objectSelect;
+    }
+    
+    public JRadioButton getSqlSelect()
+    {
+        return sqlSelect;
+    }
+    
+    public JRadioButton getProcedureSelect()
+    {
+        return procedureSelect;
+    }
+    
+    public JRadioButton getEjbqlSelect()
+    {
+        return ejbqlSelect;
+    }
+}



Mime
View raw message