diff --git a/ccm-cms/src/com/arsdigita/cms/ui/item/ItemLanguagesTable.java b/ccm-cms/src/com/arsdigita/cms/ui/item/ItemLanguagesTable.java
index 5c26ed831..a9c5a33a3 100755
--- a/ccm-cms/src/com/arsdigita/cms/ui/item/ItemLanguagesTable.java
+++ b/ccm-cms/src/com/arsdigita/cms/ui/item/ItemLanguagesTable.java
@@ -18,31 +18,26 @@
*/
package com.arsdigita.cms.ui.item;
-import com.arsdigita.bebop.Component;
-import com.arsdigita.bebop.ControlLink;
-import com.arsdigita.bebop.Label;
-import com.arsdigita.bebop.Link;
-import com.arsdigita.bebop.PageState;
-import com.arsdigita.bebop.Table;
+import com.arsdigita.bebop.*;
import com.arsdigita.bebop.event.TableActionAdapter;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
-import com.arsdigita.cms.ContentBundle;
-import com.arsdigita.cms.ContentPage;
-import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.*;
+import com.arsdigita.cms.dispatcher.MultilingualItemResolver;
import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.cms.util.LanguageUtil;
+import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainObjectFactory;
-import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.toolbox.ui.DataQueryBuilder;
import com.arsdigita.toolbox.ui.DataTable;
import com.arsdigita.util.LockableImpl;
-
+import com.arsdigita.web.RedirectSignal;
+import com.arsdigita.web.URL;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
@@ -52,11 +47,13 @@ import org.apache.log4j.Logger;
*/
public class ItemLanguagesTable extends DataTable {
+ private static final Logger s_log = Logger.getLogger(ItemLanguagesTable.class);
private ItemSelectionModel m_model;
private TableColumn m_deleteColumn;
/**
- * Construct a new ItemHistoryTable
+ * Construct a new
+ * ItemHistoryTable
*
* @param model the ItemSelectionModel that supplies the current item
*/
@@ -65,12 +62,12 @@ public class ItemLanguagesTable extends DataTable {
m_model = model;
addColumn("cms.ui.language.header", ContentPage.LANGUAGE, false,
- new LanguageRenderer());
+ new LanguageCellRenderer(m_model));
addColumn("cms.title", ContentPage.TITLE);
m_deleteColumn = addColumn("cms.ui.action", new ActionCellRenderer(
m_model));
setResourceBundle(GlobalizationUtil.getBundleName());
- addTableActionListener(new InstanceDeleter());
+ addTableActionListener(new InstanceDeleter(m_model));
}
/**
@@ -88,7 +85,7 @@ public class ItemLanguagesTable extends DataTable {
public DataQuery makeDataQuery(DataTable t, PageState s) {
ContentPage multiLingual =
- (ContentPage) m_model.getSelectedObject(s);
+ (ContentPage) m_model.getSelectedObject(s);
DataQuery q = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.getBundledItems");
q.setParameter("bundleID", multiLingual.getContentBundle().getID());
@@ -103,17 +100,61 @@ public class ItemLanguagesTable extends DataTable {
/**
* Renders the full language name.
*/
- private static class LanguageRenderer implements TableCellRenderer {
+ private static class LanguageCellRenderer implements TableCellRenderer {
+
+ private ItemSelectionModel m_model;
+
+ public LanguageCellRenderer(ItemSelectionModel model) {
+ m_model = model;
+ }
public Component getComponent(Table table, PageState state, Object value,
- boolean isSelected, Object key,
- int row, int column) {
+ boolean isSelected, Object key,
+ int row, int column) {
+
BigDecimal id = (BigDecimal) key;
- String target =
- ContentItemPage.getRelativeItemURL(id,
- ContentItemPage.AUTHORING_TAB);
- return new Link(new Label(LanguageUtil.getLangFull((String) value)),
- target);
+ ContentPage cp;
+
+ try {
+ cp = new ContentPage(id);
+ } catch (DataObjectNotFoundException ex) {
+ // Content item was not found, return nothing
+ return new Label();
+ }
+
+ ContentBundle bundle = cp.getContentBundle();
+
+ if (bundle != null
+ && !(cp instanceof LanguageInvariantContentItem
+ && ((LanguageInvariantContentItem) cp).isLanguageInvariant())) {
+
+ StringBuilder fontWeight = new StringBuilder(2);
+ StringBuilder classes = new StringBuilder(20);
+
+ if (cp.isLive()) {
+ fontWeight.append(Label.BOLD);
+ classes.append("live ");
+ }
+ if (bundle.getPrimaryInstance().equals(cp)) {
+ fontWeight.append(Label.ITALIC);
+ classes.append("primaryInstance");
+ }
+
+ String target = ContentItemPage.getRelativeItemURL(id, ContentItemPage.AUTHORING_TAB);
+ Label langLabel = new Label(LanguageUtil.getLangFull((String) value));
+
+ langLabel.setFontWeight(fontWeight.toString().trim());
+ langLabel.setClassAttr(classes.toString().trim());
+
+ if (m_model.getSelectedKey(state).equals(key)) {
+ // Current instance: no link
+ return langLabel;
+ } else {
+ return new Link(langLabel, target);
+ }
+ }
+
+ return new Label();
}
}
@@ -123,10 +164,10 @@ public class ItemLanguagesTable extends DataTable {
private static class ActionCellRenderer implements TableCellRenderer {
private static final Logger logger =
- Logger.getLogger(ActionCellRenderer.class);
- private static Label s_noAction;
- private static Label s_primary;
- private static ControlLink s_link;
+ Logger.getLogger(ActionCellRenderer.class);
+ private static final Label s_noAction;
+ private static final Label s_primary;
+ private static final ControlLink s_link;
static {
logger.debug("Static initializer is starting...");
@@ -137,7 +178,8 @@ public class ItemLanguagesTable extends DataTable {
s_primary.lock();
s_link = new ControlLink(new Label(GlobalizationUtil.globalize(
"cms.ui.delete")));
- s_link.setConfirmation("Permanently delete this item?"); // XXX G11N ?
+ s_link.setConfirmation(GlobalizationUtil.globalize(
+ "cms.ui.delete_confirmation"));
logger.debug("Static initalizer finished.");
}
private ItemSelectionModel m_model;
@@ -147,34 +189,39 @@ public class ItemLanguagesTable extends DataTable {
}
public Component getComponent(Table table, PageState state, Object value,
- boolean isSelected, Object key,
- int row, int column) {
- if (m_model.getSelectedKey(state).equals(key)) {
- return s_noAction;
- } else {
- // check if primary instance
- BigDecimal id = new BigDecimal(key.toString());
- OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
- try {
- ContentPage item = (ContentPage) DomainObjectFactory.
- newInstance(oid);
- if (item.getLanguage().equals(
- item.getContentBundle().getDefaultLanguage())) {
- return s_primary;
- } else if (item.getLiveVersion() != null) {
- return s_noAction;
- }
- } catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
+ boolean isSelected, Object key,
+ int row, int column) {
+ // check if primary instance
+ BigDecimal id = new BigDecimal(key.toString());
+ OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
+ try {
+ ContentPage item = (ContentPage) DomainObjectFactory.newInstance(oid);
+ if (item.getLanguage().equals(
+ item.getContentBundle().getDefaultLanguage())) {
+ return s_primary;
+ } else if (item.isLive()) {
return s_noAction;
}
- return s_link;
+ } catch (DataObjectNotFoundException ex) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Could not get item with id " + id);
+ }
+ return s_noAction;
}
+ return s_link;
}
}
// delete one language instance
private class InstanceDeleter extends TableActionAdapter {
+ private ItemSelectionModel m_model;
+
+ public InstanceDeleter(ItemSelectionModel model) {
+ m_model = model;
+ }
+
+ @Override
public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue();
@@ -188,10 +235,14 @@ public class ItemLanguagesTable extends DataTable {
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
try {
ContentPage item =
- (ContentPage) DomainObjectFactory.newInstance(oid);
+ (ContentPage) DomainObjectFactory.newInstance(oid);
ContentBundle bundle = item.getContentBundle();
bundle.removeInstance(item);
item.delete();
+
+ if (m_model.getSelectedKey(s).equals(id)) {
+ throw new RedirectSignal(URL.there((new MultilingualItemResolver().generateItemURL(s, bundle.getPrimaryInstance(), bundle.getContentSection(), ContentItem.DRAFT)), null), true);
+ }
} catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
// Object not found is ok, it has probably been deleted already
}