ItemLanguagesTable
* Löschen-Link für Sprachvariante (#1065) wird nun angezeigt * Primary Instance wird immer angezeigt * Sprache erhält nun die gleiche Formatierung, wie die Sprach-Spalte im FolderBrowser * Löschbestätigung ist lokalisiert * Löschen der aktuellen Sprachvariante erzeugt ein RedirectSignal, so daß man hinterher in der primären Instanz ist git-svn-id: https://svn.libreccm.org/ccm/trunk@1584 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
d97675dee5
commit
5fc056c4f2
|
|
@ -18,31 +18,26 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.item;
|
package com.arsdigita.cms.ui.item;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
import com.arsdigita.bebop.*;
|
||||||
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.event.TableActionAdapter;
|
import com.arsdigita.bebop.event.TableActionAdapter;
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
import com.arsdigita.bebop.event.TableActionEvent;
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
import com.arsdigita.bebop.table.TableColumn;
|
||||||
import com.arsdigita.cms.ContentBundle;
|
import com.arsdigita.cms.*;
|
||||||
import com.arsdigita.cms.ContentPage;
|
import com.arsdigita.cms.dispatcher.MultilingualItemResolver;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
import com.arsdigita.cms.ui.ContentItemPage;
|
||||||
import com.arsdigita.cms.util.GlobalizationUtil;
|
import com.arsdigita.cms.util.GlobalizationUtil;
|
||||||
import com.arsdigita.cms.util.LanguageUtil;
|
import com.arsdigita.cms.util.LanguageUtil;
|
||||||
|
import com.arsdigita.domain.DataObjectNotFoundException;
|
||||||
import com.arsdigita.domain.DomainObjectFactory;
|
import com.arsdigita.domain.DomainObjectFactory;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.persistence.DataQuery;
|
import com.arsdigita.persistence.DataQuery;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
import com.arsdigita.persistence.SessionManager;
|
import com.arsdigita.persistence.SessionManager;
|
||||||
import com.arsdigita.toolbox.ui.DataQueryBuilder;
|
import com.arsdigita.toolbox.ui.DataQueryBuilder;
|
||||||
import com.arsdigita.toolbox.ui.DataTable;
|
import com.arsdigita.toolbox.ui.DataTable;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
import com.arsdigita.web.RedirectSignal;
|
||||||
|
import com.arsdigita.web.URL;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -52,11 +47,13 @@ import org.apache.log4j.Logger;
|
||||||
*/
|
*/
|
||||||
public class ItemLanguagesTable extends DataTable {
|
public class ItemLanguagesTable extends DataTable {
|
||||||
|
|
||||||
|
private static final Logger s_log = Logger.getLogger(ItemLanguagesTable.class);
|
||||||
private ItemSelectionModel m_model;
|
private ItemSelectionModel m_model;
|
||||||
private TableColumn m_deleteColumn;
|
private TableColumn m_deleteColumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new <code>ItemHistoryTable</code>
|
* Construct a new
|
||||||
|
* <code>ItemHistoryTable</code>
|
||||||
*
|
*
|
||||||
* @param model the ItemSelectionModel that supplies the current item
|
* @param model the ItemSelectionModel that supplies the current item
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,12 +62,12 @@ public class ItemLanguagesTable extends DataTable {
|
||||||
m_model = model;
|
m_model = model;
|
||||||
|
|
||||||
addColumn("cms.ui.language.header", ContentPage.LANGUAGE, false,
|
addColumn("cms.ui.language.header", ContentPage.LANGUAGE, false,
|
||||||
new LanguageRenderer());
|
new LanguageCellRenderer(m_model));
|
||||||
addColumn("cms.title", ContentPage.TITLE);
|
addColumn("cms.title", ContentPage.TITLE);
|
||||||
m_deleteColumn = addColumn("cms.ui.action", new ActionCellRenderer(
|
m_deleteColumn = addColumn("cms.ui.action", new ActionCellRenderer(
|
||||||
m_model));
|
m_model));
|
||||||
setResourceBundle(GlobalizationUtil.getBundleName());
|
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) {
|
public DataQuery makeDataQuery(DataTable t, PageState s) {
|
||||||
ContentPage multiLingual =
|
ContentPage multiLingual =
|
||||||
(ContentPage) m_model.getSelectedObject(s);
|
(ContentPage) m_model.getSelectedObject(s);
|
||||||
DataQuery q = SessionManager.getSession().retrieveQuery(
|
DataQuery q = SessionManager.getSession().retrieveQuery(
|
||||||
"com.arsdigita.cms.getBundledItems");
|
"com.arsdigita.cms.getBundledItems");
|
||||||
q.setParameter("bundleID", multiLingual.getContentBundle().getID());
|
q.setParameter("bundleID", multiLingual.getContentBundle().getID());
|
||||||
|
|
@ -103,17 +100,61 @@ public class ItemLanguagesTable extends DataTable {
|
||||||
/**
|
/**
|
||||||
* Renders the full language name.
|
* 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,
|
public Component getComponent(Table table, PageState state, Object value,
|
||||||
boolean isSelected, Object key,
|
boolean isSelected, Object key,
|
||||||
int row, int column) {
|
int row, int column) {
|
||||||
|
|
||||||
BigDecimal id = (BigDecimal) key;
|
BigDecimal id = (BigDecimal) key;
|
||||||
String target =
|
ContentPage cp;
|
||||||
ContentItemPage.getRelativeItemURL(id,
|
|
||||||
ContentItemPage.AUTHORING_TAB);
|
try {
|
||||||
return new Link(new Label(LanguageUtil.getLangFull((String) value)),
|
cp = new ContentPage(id);
|
||||||
target);
|
} 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 class ActionCellRenderer implements TableCellRenderer {
|
||||||
|
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
Logger.getLogger(ActionCellRenderer.class);
|
Logger.getLogger(ActionCellRenderer.class);
|
||||||
private static Label s_noAction;
|
private static final Label s_noAction;
|
||||||
private static Label s_primary;
|
private static final Label s_primary;
|
||||||
private static ControlLink s_link;
|
private static final ControlLink s_link;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
logger.debug("Static initializer is starting...");
|
logger.debug("Static initializer is starting...");
|
||||||
|
|
@ -137,7 +178,8 @@ public class ItemLanguagesTable extends DataTable {
|
||||||
s_primary.lock();
|
s_primary.lock();
|
||||||
s_link = new ControlLink(new Label(GlobalizationUtil.globalize(
|
s_link = new ControlLink(new Label(GlobalizationUtil.globalize(
|
||||||
"cms.ui.delete")));
|
"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.");
|
logger.debug("Static initalizer finished.");
|
||||||
}
|
}
|
||||||
private ItemSelectionModel m_model;
|
private ItemSelectionModel m_model;
|
||||||
|
|
@ -147,34 +189,39 @@ public class ItemLanguagesTable extends DataTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getComponent(Table table, PageState state, Object value,
|
public Component getComponent(Table table, PageState state, Object value,
|
||||||
boolean isSelected, Object key,
|
boolean isSelected, Object key,
|
||||||
int row, int column) {
|
int row, int column) {
|
||||||
if (m_model.getSelectedKey(state).equals(key)) {
|
// check if primary instance
|
||||||
return s_noAction;
|
BigDecimal id = new BigDecimal(key.toString());
|
||||||
} else {
|
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
|
||||||
// check if primary instance
|
try {
|
||||||
BigDecimal id = new BigDecimal(key.toString());
|
ContentPage item = (ContentPage) DomainObjectFactory.newInstance(oid);
|
||||||
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
|
if (item.getLanguage().equals(
|
||||||
try {
|
item.getContentBundle().getDefaultLanguage())) {
|
||||||
ContentPage item = (ContentPage) DomainObjectFactory.
|
return s_primary;
|
||||||
newInstance(oid);
|
} else if (item.isLive()) {
|
||||||
if (item.getLanguage().equals(
|
|
||||||
item.getContentBundle().getDefaultLanguage())) {
|
|
||||||
return s_primary;
|
|
||||||
} else if (item.getLiveVersion() != null) {
|
|
||||||
return s_noAction;
|
|
||||||
}
|
|
||||||
} catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
|
|
||||||
return s_noAction;
|
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
|
// delete one language instance
|
||||||
private class InstanceDeleter extends TableActionAdapter {
|
private class InstanceDeleter extends TableActionAdapter {
|
||||||
|
|
||||||
|
private ItemSelectionModel m_model;
|
||||||
|
|
||||||
|
public InstanceDeleter(ItemSelectionModel model) {
|
||||||
|
m_model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void cellSelected(TableActionEvent e) {
|
public void cellSelected(TableActionEvent e) {
|
||||||
int col = e.getColumn().intValue();
|
int col = e.getColumn().intValue();
|
||||||
|
|
||||||
|
|
@ -188,10 +235,14 @@ public class ItemLanguagesTable extends DataTable {
|
||||||
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
|
OID oid = new OID(ContentPage.BASE_DATA_OBJECT_TYPE, id);
|
||||||
try {
|
try {
|
||||||
ContentPage item =
|
ContentPage item =
|
||||||
(ContentPage) DomainObjectFactory.newInstance(oid);
|
(ContentPage) DomainObjectFactory.newInstance(oid);
|
||||||
ContentBundle bundle = item.getContentBundle();
|
ContentBundle bundle = item.getContentBundle();
|
||||||
bundle.removeInstance(item);
|
bundle.removeInstance(item);
|
||||||
item.delete();
|
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) {
|
} catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
|
||||||
// Object not found is ok, it has probably been deleted already
|
// Object not found is ok, it has probably been deleted already
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue