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;
|
||||
|
||||
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 <code>ItemHistoryTable</code>
|
||||
* Construct a new
|
||||
* <code>ItemHistoryTable</code>
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -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) {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,9 +165,9 @@ public class ItemLanguagesTable extends DataTable {
|
|||
|
||||
private static final Logger logger =
|
||||
Logger.getLogger(ActionCellRenderer.class);
|
||||
private static Label s_noAction;
|
||||
private static Label s_primary;
|
||||
private static ControlLink s_link;
|
||||
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;
|
||||
|
|
@ -149,32 +191,37 @@ 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);
|
||||
ContentPage item = (ContentPage) DomainObjectFactory.newInstance(oid);
|
||||
if (item.getLanguage().equals(
|
||||
item.getContentBundle().getDefaultLanguage())) {
|
||||
return s_primary;
|
||||
} else if (item.getLiveVersion() != null) {
|
||||
} else if (item.isLive()) {
|
||||
return s_noAction;
|
||||
}
|
||||
} catch (com.arsdigita.domain.DataObjectNotFoundException ex) {
|
||||
} 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();
|
||||
|
||||
|
|
@ -192,6 +239,10 @@ public class ItemLanguagesTable extends DataTable {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue