ItemLanguages.
*
- * @param selectionModel the {@link ItemSelectionModel} which will supply the current
- * item
+ * @param selectionModel the {@link ItemSelectionModel} which will supply
+ * the current item
*/
public ItemLanguages(final ItemSelectionModel selectionModel) {
this.selectionModel = selectionModel;
@@ -91,9 +90,11 @@ public class ItemLanguages extends LayoutPanel {
form.setRedirecting(true);
languageWidget = new LanguageWidget(ContentItem.LANGUAGE) {
+
protected void setupOptions() {
// Don't do anything.
}
+
};
try {
@@ -119,18 +120,20 @@ public class ItemLanguages extends LayoutPanel {
final PageState state = e.getPageState();
final OptionGroup optionGroup = (OptionGroup) e.getTarget();
final ContentPage item = (ContentPage) selectionModel.
- getSelectedItem(state);
+ getSelectedItem(state);
final Collection languages = LanguageUtil.convertToG11N(
- LanguageUtil.getCreatableLanguages(item));
+ LanguageUtil.getCreatableLanguages(item));
for (Iterator iter = languages.iterator(); iter.hasNext();) {
final Pair pair = (Pair) iter.next();
final String langCode = (String) pair.getKey();
final GlobalizedMessage langName
- = (GlobalizedMessage) pair.getValue();
+ = (GlobalizedMessage) pair
+ .getValue();
optionGroup.addOption(new Option(langCode, new Label(langName)));
}
}
+
}
/**
@@ -139,10 +142,11 @@ public class ItemLanguages extends LayoutPanel {
private class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e)
- throws FormProcessException {
+ throws FormProcessException {
PageState state = e.getPageState();
String lang = (String) languageWidget.getValue(state);
- ContentPage item = (ContentPage) selectionModel.getSelectedItem(state);
+ ContentPage item = (ContentPage) selectionModel.getSelectedItem(
+ state);
ContentBundle bundle = item.getContentBundle();
String name = bundle.getName();
@@ -159,8 +163,8 @@ public class ItemLanguages extends LayoutPanel {
// Apply default workflow
WorkflowTemplate template
- = ContentTypeWorkflowTemplate
- .getWorkflowTemplate(section, type);
+ = ContentTypeWorkflowTemplate
+ .getWorkflowTemplate(section, type);
if (template != null) {
Workflow w = template.instantiateNewWorkflow();
w.setObjectID(item.getID());
@@ -172,8 +176,8 @@ public class ItemLanguages extends LayoutPanel {
// redirect to ContentItemPage.AUTHORING_TAB of the new instance
final String target = URL.getDispatcherPath() + ContentItemPage.
- getItemURL(item,
- ContentItemPage.AUTHORING_TAB);
+ getItemURL(item,
+ ContentItemPage.AUTHORING_TAB);
throw new RedirectSignal(target, true);
} else if (changeSubmit.isSelected(state)) {
@@ -191,6 +195,7 @@ public class ItemLanguages extends LayoutPanel {
}
}
}
+
}
protected static final GlobalizedMessage gz(final String key) {
@@ -200,4 +205,5 @@ public class ItemLanguages extends LayoutPanel {
protected static final String lz(final String key) {
return (String) gz(key).localize();
}
+
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java.todo
index 0aa27f364..3f8007e09 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java.todo
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java.todo
@@ -18,7 +18,6 @@
*/
package com.arsdigita.cms.ui.item;
-import com.arsdigita.bebop.*;
import com.arsdigita.bebop.event.TableActionAdapter;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.table.TableCellRenderer;
diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/event/EventListenerList.java b/ccm-core/src/main/java/com/arsdigita/bebop/event/EventListenerList.java
index 2a1e756f7..5806849d5 100755
--- a/ccm-core/src/main/java/com/arsdigita/bebop/event/EventListenerList.java
+++ b/ccm-core/src/main/java/com/arsdigita/bebop/event/EventListenerList.java
@@ -24,7 +24,7 @@ import java.util.NoSuchElementException;
/**
* Convenience extensions to {@link javax.swing.event.EventListenerList
* Swing's EventListenerList}.
- * @version $Id$
+ *
*/
public class EventListenerList extends javax.swing.event.EventListenerList {
diff --git a/ccm-core/src/main/java/com/arsdigita/toolbox/ui/AbstractDataQueryBuilder.java.todo b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/AbstractDataQueryBuilder.java.todo
new file mode 100644
index 000000000..c2279b2aa
--- /dev/null
+++ b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/AbstractDataQueryBuilder.java.todo
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2016 LibreCCM Foundation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301 USA
+ */
+package com.arsdigita.toolbox.ui;
+
+import org.libreccm.cdi.utils.CdiUtil;
+
+import javax.persistence.criteria.CriteriaQuery;
+
+/**
+ *
+ * @author Jens Pelzetter
+ * @param DataQueryBuilder may dynamically
+ * construct the query during each request, or return the same named query for
+ * each request; the DataTable does not care where the query comes
+ * from.
+ *
+ * This class may contain multiple {@link QueryListener}s. These listeners will
+ * be fired whenever the query is about to be performed, thus giving the user a
+ * chance to set additional filters on the query.
+ *
+ * Columns may be added to the DataTable by calling the
+ * {@link #addColumn} method. The user may choose to make the column sortable or
+ * non-sortable; sortable columns will appear as links on the Web page which,
+ * when clicked, will sort the table by the specified column. See the
+ * documentation on the various addColumn methods for more
+ * information.
+ *
+ *
+ * This class sets the XSL "class" attribute to "dataTable"
+ *
+ * DataTable also implements {@link PaginationModelBuilder}. This
+ * means that it could serve as the model builder for any {@link Paginator}
+ * component. Pagination of the query occurs after all the sorting and query
+ * events have finished. Consider a query which returns the rows "A B C D E F".
+ * If the paginator displays 3 rows per page, page 1 will contain "A B C" and
+ * page 2 will contain "D E F". If the user then clicks on the header in the
+ * DataTable, causing the query to be sorted in reverse order, page
+ * 1 will contain "F E D" and page 2 will contain "C B A". In order for
+ * pagination to work properly, the following pattern must be used:
+ *
+ * + * + * The+ * DataTable table = new DataTable(...); + * Paginator paginator = new Paginator(table, ...); + * table.setPaginator(paginator); + *
setPaginator call is required due to a design flaw in the
+ * Paginator component.
+ * + * + *
DataTable will ordinarily interpret the labels of its column
+ * headers as plain text, and spit them out on the screen verbatim. However, if
+ * setResouceBundle is called, DataTable will instead
+ * interpret the column header labels as keys into the specified resource
+ * bundle, thus attempting to globalize the column headers at runtime.
+ *
+ *
+ * @author Stanislav Freidin
+ * @author Jens Pelzetter
+ * @param
+ * Also, globalizes the column labels if possible.
+ */
+ protected static class GlobalizedHeaderCellRenderer
+ implements TableCellRenderer {
+
+ private boolean m_active;
+
+ public GlobalizedHeaderCellRenderer(boolean isActive) {
+ m_active = isActive;
+ }
+
+ public GlobalizedHeaderCellRenderer() {
+ this(true);
+ }
+
+ public Component getComponent(Table table, PageState state, Object value,
+ boolean isSelected, Object key,
+ int row, int column) {
+ DataTable t = (DataTable) table;
+ Label label;
+
+ if (value == null) {
+ label = new Label(" ", false);
+ } else {
+ String str = value.toString();
+ if (t.getResourceBundle() != null) {
+ label = new Label(t.globalize(str));
+ } else {
+ label = new Label(str);
+ }
+ }
+
+ if (m_active) {
+ return new ControlLink(label);
+ } else {
+ return label;
+ }
+ }
+
+ }
+
+ /**
+ * A special column model that maintains an alternate key for each column.
+ * The alternate key will be passed to the query in the
+ *
+ * Note that each column ALREADY has a unique key, which can be retrieved by
+ * calling DataQuery
+ * which will be used as the value for this column.
+ * @param isSortable true if it is possible to sort using this column, false
+ * otherwise
+ * @param renderer a {@link TableCellRenderer} that will be used to format
+ * the attribute as a string.
+ *
+ * @return the newly added column
+ */
+ public TableColumn addColumn(final String label,
+ final String attribute,
+ final boolean isSortable,
+ final TableCellRenderer renderer) {
+ return addColumn(label, attribute, isSortable, renderer, null);
+ }
+
+ /**
+ * Add a column to this table.
+ *
+ * @param label The user-readable label for the column NOTE:
+ * depending on setResourceBundle() it is treated as
+ * plain text for output or key into bundle resulting
+ * in globalised Labels!
+ * @param attribute The name of the attribute in the
+ * DataQuery which will be used as the
+ * value for this column.
+ * @param isSortable true if it is possible to sort using this column,
+ * false otherwise
+ * @param renderer a {@link TableCellRenderer} that will be used to
+ * format the attribute as a string.
+ * @param orderAttribute The name of the attribute which will be used as the
+ * column to order by. This key may be different from
+ * the attribute parameter.
+ *
+ * @return the newly added column
+ */
+ public TableColumn addColumn(final String label,
+ final String attribute,
+ final boolean isSortable,
+ final TableCellRenderer renderer,
+ final String orderAttribute) {
+ DataTableColumnModel model = (DataTableColumnModel) getColumnModel();
+ TableColumn column = new SortableTableColumn(model.size(),
+ label,
+ attribute,
+ isSortable,
+ renderer
+ );
+
+ model.add(column, orderAttribute);
+
+ // Update the default sort order
+ if (isSortable && getDefaultOrder() == null) {
+ setDefaultOrder((orderAttribute == null) ? attribute
+ : orderAttribute);
+ }
+
+ return column;
+ }
+
+ /**
+ * Add a column to this table.
+ *
+ * @param label The user-readable label for the column NOTE: depending
+ * on setResourceBundle() it is treated as plain text for
+ * output or key into bundle resulting in globalized
+ * Labels!
+ * @param attribute The name of the attribute in the DataQuery
+ * which will be used as the value for this column.
+ * @param isSortable true if it is possible to sort using this column, false
+ * otherwise
+ *
+ * @return the newly added column
+ */
+ public TableColumn addColumn(final String label,
+ final String attribute,
+ final boolean isSortable) {
+ return addColumn(label,
+ attribute,
+ isSortable,
+ new DefaultTableCellRenderer(false));
+ }
+
+ /**
+ * Add a column to this table.
+ *
+ * @param label The user-readable label for the column NOTE: depending
+ * on setResourceBundle() it is treated as plain text for
+ * output or key into bundle resulting in globalized
+ * Labels!
+ * @param attribute The name of the attribute in the DataQuery
+ * which will be used as the value for this column.
+ *
+ * @return the newly added column
+ */
+ public TableColumn addColumn(final String label, final String attribute) {
+ return addColumn(label, attribute, false);
+ }
+
+ /**
+ * Add a column to this table. The value for the column will not be supplied
+ * by the query; instead, it is the user's responsibility to supply the
+ * value through a custom {@link TableModel} or render it directly in the
+ * {@link TableCellRenderer}. Typically, this method will be used to add
+ * {@link ControlLink}s to the table.
+ *
+ * @param label The user-readable label for the column NOTE: depending on
+ * setResourceBundle() it is treated as plain text for
+ * output or key into bundle resulting in globalized Labels!
+ * @param renderer The cell renderer for the given column
+ *
+ * @return the newly added column
+ */
+ public TableColumn addColumn(final String label,
+ final TableCellRenderer renderer) {
+ final TableColumnModel columnModel = getColumnModel();
+ final TableColumn column = new TableColumn(columnModel.size(), label);
+ column.setCellRenderer(renderer);
+ column.setHeaderRenderer(new GlobalizedHeaderCellRenderer(false));
+ columnModel.add(column);
+ return column;
+ }
+
+ /**
+ *
+ * @return the {@link DataQueryBuilder} that creates a {@link DataQuery} for
+ * this table during each request
+ */
+ public DataQueryBuilderDataQuery
+ */
+ public CriteriaQueryDataTable has been added as the model builder.
+ *
+ * @param paginator the parent Paginator
+ * @param state the current page state
+ *
+ * @return the total number of rows in the query
+ */
+ @Override
+ public int getTotalSize(final Paginator paginator, final PageState state) {
+ final CriteriaQueryDataBuilderAdapter
+ */
+ public DataBuilderAdapter() {
+ super();
+ }
+
+ /**
+ * Obtain a {@link DataQuery} and apply query events to it. The query
+ * events may add additional filters to the query, among other things.
+ * Finally, retrieve the current sort column from the parent
+ * {@link DataTable} and apply it to the query
+ *
+ * @see com.arsdigita.toolbox.ui.DataTable.DataQueryTableModel
+ * @param table the parent {@link DataTable}
+ * @param state the current page state
+ *
+ * @return the final {@link DataQuery}, which is now ready to be wrapped
+ * in a DataQueryTableModel
+ */
+ protected DataQueryTableModel
+ *
+ * @param t the {@link DataTable} which needs this model
+ * @param data the {@link DataQuery to be wrapped}
+ * @param keyColumn the name of the column in the query which represents
+ * the primary key
+ *
+ * @pre data != null
+ * @pre keyColumn != null
+ * @pre t != null
+ * @pre t.getColumnModel() != null
+ */
+ public DataQueryTableModel(DataTable t, DataQuery data, String keyColumn) {
+ m_data = data;
+ m_cols = (DataTableColumnModel) t.getColumnModel();
+ m_keyColumn = keyColumn;
+ }
+
+ public int getColumnCount() {
+ return m_cols.size();
+ }
+
+ public boolean nextRow() {
+ return m_data.next();
+ }
+
+ public Object getElementAt(int columnIndex) {
+ String key = (String) m_cols.get(columnIndex).getHeaderKey();
+ if (key != null) {
+ return m_data.get(key);
+ } else {
+ return null;
+ }
+ }
+
+ public Object getKeyAt(int columnIndex) {
+ String key = m_cols.getKeyAt(columnIndex);
+ if (key != null) {
+ return m_data.get(key);
+ } else {
+ return m_data.get(m_keyColumn);
+ }
+ }
+
+ /**
+ * Return the original DataQuery. The query's cursor will be "pointing"
+ * at the current row
+ */
+ public DataQuery getDataQuery() {
+ return m_data;
+ }
+
+ }
+
+ /**
+ * Always renders the table header as a link. Thus, it becomes possible to
+ * sort up and down by clicking the table column over and over.addOrder method, thus sorting the query by the given column
+ * - making it possible to make the sort key differ from the attribute key
+ * for any given column.
+ * TableColumn.getHeaderKey(). This key will be used to
+ * provide the value for the column.
+ */
+ protected static class DataTableColumnModel extends DefaultTableColumnModel {
+
+ // The column keys are a property of the table and column
+ // combination so we store the values in the HashMap
+ private Map m_columnKeys = new HashMap();
+
+ public void add(TableColumn column, String columnKey) {
+ super.add(column);
+ setColumnKey(column, columnKey);
+ }
+
+ public void add(int columnIndex, TableColumn column, String columnKey) {
+ super.add(columnIndex, column);
+ setColumnKey(column, columnKey);
+ }
+
+ public String getColumnKey(TableColumn column) {
+ return (String) m_columnKeys.get(column);
+ }
+
+ public String getKeyAt(int columnIndex) {
+ return getColumnKey(get(columnIndex));
+ }
+
+ public void setColumnKey(TableColumn column, String columnKey) {
+ m_columnKeys.put(column, columnKey);
+ }
+
+ public void setColumnKey(int columnIndex, String columnKey) {
+ setColumnKey(get(columnIndex), columnKey);
+ }
+
+ @Override
+ public void remove(TableColumn column) {
+ super.remove(column);
+ m_columnKeys.remove(column);
+ }
+
+ }
+
+}
diff --git a/ccm-core/src/main/java/com/arsdigita/toolbox/ui/QueryEvent.java b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/QueryEvent.java
new file mode 100755
index 000000000..fa5dae504
--- /dev/null
+++ b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/QueryEvent.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+package com.arsdigita.toolbox.ui;
+
+import com.arsdigita.bebop.Component;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.event.PageEvent;
+
+import javax.persistence.criteria.CriteriaQuery;
+
+/**
+ * This event is fired by the {@link DataTable} class
+ *
+ * @param