X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=eclipse%2Fplugins%2Forg.argeo.slc.client.ui.dist%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fclient%2Fui%2Fdist%2Fviews%2FAbstractQueryArtifactsView.java;h=940d8687cb17e2e3ef96557d2d169984f84c6972;hb=868102c0f0220e12eca836b6ec9b3a2b9a3441e4;hp=2605cff8ca53d44f1850aa4ba2ee886fd9525976;hpb=0c757117d51669137b04b65a52dca20b856ea413;p=gpl%2Fargeo-slc.git diff --git a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/AbstractQueryArtifactsView.java b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/AbstractQueryArtifactsView.java index 2605cff8c..940d8687c 100644 --- a/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/AbstractQueryArtifactsView.java +++ b/eclipse/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/AbstractQueryArtifactsView.java @@ -1,8 +1,24 @@ +/* + * 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.slc.client.ui.dist.views; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.Iterator; import java.util.List; import javax.jcr.RepositoryException; @@ -17,6 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.argeo.ArgeoException; import org.argeo.eclipse.ui.GenericTableComparator; import org.argeo.slc.client.ui.dist.utils.ArtifactsTableConfigurer; +import org.argeo.slc.client.ui.dist.utils.GenericDoubleClickListener; import org.argeo.slc.jcr.SlcTypes; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -41,8 +58,15 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements private static final Log log = LogFactory .getLog(AbstractQueryArtifactsView.class); + // shortcuts + final protected static String SAVB = "[" + SLC_ARTIFACT_VERSION_BASE + "]"; + final protected static String SBA = "[" + SLC_BUNDLE_ARTIFACT + "]"; + final protected static String SIP = "[" + SLC_IMPORTED_PACKAGE + "]"; + final protected static String SEP = "[" + SLC_EXPORTED_PACKAGE + "]"; + /* DEPENDENCY INJECTION */ private Session session; + private List columnProperties; // This page widgets private TableViewer viewer; @@ -50,6 +74,9 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements private ArtifactsTableConfigurer tableConfigurer; private GenericTableComparator comparator; + // to be set by client to display all columns + private boolean displayAllColumns = false; + protected void createResultPart(Composite parent) { viewer = new TableViewer(parent); Table table = viewer.getTable(); @@ -60,7 +87,8 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements viewer.setLabelProvider(new ViewLabelProvider()); viewer.setContentProvider(new ViewContentProvider()); - // viewer.addDoubleClickListener(new ViewDoubleClickListener()); + viewer.addDoubleClickListener(new GenericDoubleClickListener(null)); + tableConfigurer = new ArtifactsTableConfigurer(viewer, 1, GenericTableComparator.DESCENDING); @@ -87,19 +115,39 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements // remove previous columns for (TableViewerColumn tvc : tableViewerColumns) tvc.getColumn().dispose(); - int i = 0; - for (final String columnName : qr.getColumnNames()) { - TableViewerColumn tvc = new TableViewerColumn(viewer, SWT.NONE); - // Small hack to remove prefix from the column name - String tmpStr = columnName.substring(columnName - .lastIndexOf(".")+1); - tableConfigurer.configureColumn(tmpStr, tvc, i); - tvc.setLabelProvider(tableConfigurer - .getLabelProvider(columnName)); - tableViewerColumns.add(tvc); - i++; - } + // If a pre(-defined list of columns has been injected, we use it, + // otherwise we display all results of the resultSet + if (!displayAllColumns && columnProperties != null) { + int i = 0; + + Iterator it = columnProperties.iterator(); + while (it.hasNext()) { + String columnName = it.next(); + + TableViewerColumn tvc = new TableViewerColumn(viewer, + SWT.NONE); + tableConfigurer.configureColumn(columnName, tvc, i); + tvc.setLabelProvider(tableConfigurer + .getLabelProvider(columnName)); + tableViewerColumns.add(tvc); + i++; + } + } else { + int i = 0; + for (final String columnName : qr.getColumnNames()) { + TableViewerColumn tvc = new TableViewerColumn(viewer, + SWT.NONE); + // Small hack to remove prefix from the column name + // String tmpStr = columnName.substring(columnName + // .lastIndexOf(".") + 1); + tableConfigurer.configureColumn(columnName, tvc, i); + tvc.setLabelProvider(tableConfigurer + .getLabelProvider(columnName)); + tableViewerColumns.add(tvc); + i++; + } + } // We must create a local list because query result can be read only // once. try { @@ -120,16 +168,24 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements } } + /** + * Client must use this method to display all columns of the result set + * instead of a limited predifined and injected set + **/ + public void displayAllColumns(boolean flag) { + displayAllColumns = flag; + } + // Can be overridden by subclasses. protected String generateSelectStatement() { - StringBuffer sb = new StringBuffer("select * "); + StringBuffer sb = new StringBuffer("select " + SAVB + ".* "); return sb.toString(); } protected String generateFromStatement() { - StringBuffer sb = new StringBuffer(" from ["); - sb.append(SLC_ARTIFACT); - sb.append("] "); + StringBuffer sb = new StringBuffer(" from "); + sb.append(SAVB); + sb.append(" "); return sb.toString(); } @@ -168,4 +224,8 @@ public abstract class AbstractQueryArtifactsView extends ViewPart implements public void setSession(Session session) { this.session = session; } + + public void setColumnProperties(List columnProperties) { + this.columnProperties = columnProperties; + } } \ No newline at end of file