]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - eclipse/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/editors/AbstractJcrQueryEditor.java
Update license headers
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui.jcr / src / main / java / org / argeo / eclipse / ui / jcr / editors / AbstractJcrQueryEditor.java
index 482f9f9d4b69879ee1e56e3c367b4bfb1d949337..f41c7ca80c12460630d0500e43677ff9976a466f 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2007-2012 Mathieu Baudier
+ *
+ * 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.argeo.eclipse.ui.jcr.editors;
 
 import java.util.ArrayList;
@@ -9,6 +24,8 @@ import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.GenericTableComparator;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,17 +55,21 @@ import org.eclipse.ui.part.EditorPart;
 
 /** Executes any JCR query. */
 public abstract class AbstractJcrQueryEditor extends EditorPart {
+       private final static Log log = LogFactory
+                       .getLog(AbstractJcrQueryEditor.class);
 
        protected String initialQuery;
        protected String initialQueryType;
 
-       // IoC
+       /* DEPENDENCY INJECTION */
        private Session session;
 
+       // Widgets
        private TableViewer viewer;
        private List<TableViewerColumn> tableViewerColumns = new ArrayList<TableViewerColumn>();
        private GenericTableComparator comparator;
 
+       /** Override to layout a form enabling the end user to build his query */
        protected abstract void createQueryForm(Composite parent);
 
        @Override
@@ -97,6 +118,9 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
 
        protected void executeQuery(String statement) {
                try {
+                       if (log.isDebugEnabled())
+                               log.debug("Query : " + statement);
+
                        QueryResult qr = session.getWorkspace().getQueryManager()
                                        .createQuery(statement, initialQueryType).execute();
 
@@ -113,10 +137,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
                                i++;
                        }
 
-                       // We must create a local list because query result can be read only
-                       // once.
-                       // viewer.setInput(qr);
-
+                       // Must create a local list: QueryResults can only be read once.
                        try {
                                List<Row> rows = new ArrayList<Row>();
                                RowIterator rit = qr.getRows();
@@ -132,8 +153,6 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
                        ErrorDialog.openError(null, "Error", "Cannot execute JCR query: "
                                        + statement, new Status(IStatus.ERROR,
                                        "org.argeo.eclipse.ui.jcr", e.getMessage()));
-                       // throw new ArgeoException("Cannot execute JCR query " + statement,
-                       // e);
                }
        }
 
@@ -231,7 +250,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
                public Object[] getElements(Object inputElement) {
 
                        if (inputElement instanceof List)
-                               return ((List) inputElement).toArray();
+                               return ((List<?>) inputElement).toArray();
 
                        // Never reached might be deleted in future release
                        if (!(inputElement instanceof QueryResult))
@@ -298,10 +317,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
        }
 
        /**
-        * To be overriden to enable sorting.
-        * 
-        * @author bsinou
-        * 
+        * To be overridden to enable sorting.
         */
        protected GenericTableComparator getComparator() {
                return null;
@@ -315,7 +331,6 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
        @Override
        public void doSave(IProgressMonitor monitor) {
                // TODO save the query in JCR?
-
        }
 
        @Override
@@ -327,7 +342,12 @@ public abstract class AbstractJcrQueryEditor extends EditorPart {
                return false;
        }
 
-       // IoC
+       /** Returns the injected current session */
+       protected Session getSession() {
+               return session;
+       }
+
+       /* DEPENDENCY INJECTION */
        public void setSession(Session session) {
                this.session = session;
        }