+/*
+ * 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;
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;
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<String> columnProperties;
// This page widgets
private TableViewer viewer;
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();
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setContentProvider(new ViewContentProvider());
- // viewer.addDoubleClickListener(new ViewDoubleClickListener());
+ viewer.addDoubleClickListener(new GenericDoubleClickListener(null));
+
tableConfigurer = new ArtifactsTableConfigurer(viewer, 1,
GenericTableComparator.DESCENDING);
// 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<String> 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 {
}
}
+ /**
+ * 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();
}
public void setSession(Session session) {
this.session = session;
}
+
+ public void setColumnProperties(List<String> columnProperties) {
+ this.columnProperties = columnProperties;
+ }
}
\ No newline at end of file