ClassCast Exception im PPP behoben, Klasse bei der Gelegenheit aufgeräumt

git-svn-id: https://svn.libreccm.org/ccm/trunk@2338 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2013-10-04 18:51:28 +00:00
parent 356f805ec6
commit c3c8c22446
2 changed files with 102 additions and 137 deletions

View File

@ -56,21 +56,9 @@ public class PublicPersonalProfileNavigationStep extends SimpleEditStep {
new WorkflowLockedComponentAccess(editNavItemSheet, itemModel), new WorkflowLockedComponentAccess(editNavItemSheet, itemModel),
editNavItemSheet.getSaveCancelSection().getCancelButton()); editNavItemSheet.getSaveCancelSection().getCancelButton());
/*BasicItemForm editGeneratedNavItemSheet =
new PublicPersonalProfileNavigationGeneratedAddForm(
itemModel,
this);
add(EDIT_NAV_GENERATED_ITEM_SHEET_NAME,
(String) PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.profile.generated_content.add").
localize(),
new WorkflowLockedComponentAccess(editGeneratedNavItemSheet,
itemModel),
editGeneratedNavItemSheet.getSaveCancelSection().getCancelButton());*/
PublicPersonalProfileNavigationTable navTable = PublicPersonalProfileNavigationTable navTable =
new PublicPersonalProfileNavigationTable( new PublicPersonalProfileNavigationTable(itemModel);
itemModel, this);
setDisplayComponent(navTable); setDisplayComponent(navTable);
} }
} }

View File

@ -31,6 +31,7 @@ import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel; import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel; import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder; import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSection;
@ -40,41 +41,32 @@ import com.arsdigita.cms.contenttypes.PublicPersonalProfile;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection;
import com.arsdigita.cms.dispatcher.ItemResolver; import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.apache.log4j.Logger;
/** /**
* *
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id$
*/ */
public class PublicPersonalProfileNavigationTable extends Table public class PublicPersonalProfileNavigationTable extends Table {
implements TableActionListener {
private static final Logger logger = Logger.getLogger( private final static String TABLE_COL_EDIT = "table_col_edit";
PublicPersonalProfileNavigationTable.class); private final static String TABLE_COL_TARGET = "table_col_target";
private final String TABLE_COL_EDIT = "table_col_edit"; private final static String TABLE_COL_DEL = "table_col_del";
private final String TABLE_COL_TARGET = "table_col_target"; private final ItemSelectionModel itemModel;
private final String TABLE_COL_DEL = "table_col_del";
private ItemSelectionModel itemModel;
private SimpleEditStep editStep;
public PublicPersonalProfileNavigationTable(ItemSelectionModel itemModel, public PublicPersonalProfileNavigationTable(final ItemSelectionModel itemModel) {
SimpleEditStep editStep) {
super(); super();
this.itemModel = itemModel; this.itemModel = itemModel;
this.editStep = editStep;
setEmptyView(new Label(PublicPersonalProfileGlobalizationUtil.globalize( setEmptyView(new Label(PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.nav.empty"))); "publicpersonalprofile.ui.nav.empty")));
TableColumnModel colModel = getColumnModel(); final TableColumnModel colModel = getColumnModel();
colModel.add(new TableColumn( colModel.add(new TableColumn(
0, 0,
new Label(PublicPersonalProfileGlobalizationUtil.globalize( new Label(PublicPersonalProfileGlobalizationUtil.globalize(
@ -100,27 +92,27 @@ public class PublicPersonalProfileNavigationTable extends Table
colModel.get(1).setCellRenderer(new TargetCellRenderer()); colModel.get(1).setCellRenderer(new TargetCellRenderer());
colModel.get(2).setCellRenderer(new DeleteCellRenderer()); colModel.get(2).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this); addTableActionListener(new ActionListener());
} }
private class PublicPersonalProfileNavigationTableModelBuilder private class PublicPersonalProfileNavigationTableModelBuilder
extends LockableImpl extends LockableImpl
implements TableModelBuilder { implements TableModelBuilder {
private ItemSelectionModel itemModel; private final ItemSelectionModel itemModel;
public PublicPersonalProfileNavigationTableModelBuilder( public PublicPersonalProfileNavigationTableModelBuilder(
ItemSelectionModel itemModel) { final ItemSelectionModel itemModel) {
super();
this.itemModel = itemModel; this.itemModel = itemModel;
} }
@Override @Override
public TableModel makeModel(Table table, PageState state) { public TableModel makeModel(final Table table, final PageState state) {
table.getRowSelectionModel().clearSelection(state); table.getRowSelectionModel().clearSelection(state);
PublicPersonalProfile profile = (PublicPersonalProfile) itemModel. final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.
getSelectedObject(state); getSelectedObject(state);
return new PublicPersonalProfileNavigationTableModel( return new PublicPersonalProfileNavigationTableModel(table, profile);
table, state, profile);
} }
} }
@ -128,18 +120,12 @@ public class PublicPersonalProfileNavigationTable extends Table
private class PublicPersonalProfileNavigationTableModel private class PublicPersonalProfileNavigationTableModel
implements TableModel { implements TableModel {
private Table table; private final Table table;
private String[] mockNav = new String[]{"Allgemein", "Beruflich", private final DataCollection linkCollection;
"Forschung", "Lehre", "Projekte", private final PublicPersonalProfileNavItemCollection navItems;
"Publikationen"};
private int index = -1;
private String mockNavItem;
private PublicPersonalProfile profile;
private DataCollection linkCollection;
private PublicPersonalProfileNavItemCollection navItems;
public PublicPersonalProfileNavigationTableModel( public PublicPersonalProfileNavigationTableModel(final Table table,
Table table, PageState state, PublicPersonalProfile profile) { final PublicPersonalProfile profile) {
this.table = table; this.table = table;
linkCollection = RelatedLink.getRelatedLinks( linkCollection = RelatedLink.getRelatedLinks(
profile, PublicPersonalProfile.LINK_LIST_NAME); profile, PublicPersonalProfile.LINK_LIST_NAME);
@ -157,10 +143,9 @@ public class PublicPersonalProfileNavigationTable extends Table
} }
@Override @Override
public Object getElementAt(int columnIndex) { public Object getElementAt(final int columnIndex) {
RelatedLink link = new RelatedLink(linkCollection.getDataObject()); final RelatedLink link = new RelatedLink(linkCollection.getDataObject());
String key = link.getTitle(); final String key = link.getTitle();
ContentItem targetItem = link.getTargetItem();
PublicPersonalProfileNavItem navItem; PublicPersonalProfileNavItem navItem;
navItem = navItems.getNavItem(key, GlobalizationHelper. navItem = navItems.getNavItem(key, GlobalizationHelper.
@ -173,26 +158,19 @@ public class PublicPersonalProfileNavigationTable extends Table
switch (columnIndex) { switch (columnIndex) {
case 0: case 0:
//return mockNav[index];
if (navItem.getGeneratorClass() == null) { if (navItem.getGeneratorClass() == null) {
return navItem.getLabel(); return new Label(navItem.getLabel());
} else { } else {
return String.format("%s (auto)", navItem.getLabel()); return new Label(String.format("%s (auto)", navItem.getLabel()));
} }
case 1: case 1:
/*if (navItem.getGeneratorClass() == null) { final ContentItem targetItem = link.getTargetItem();
return targetItem;
} else {
return null;
}*/
if (targetItem instanceof PublicPersonalProfile) { if (targetItem instanceof PublicPersonalProfile) {
return null; return null;
} else { } else {
return targetItem; return targetItem;
} }
case 2: case 2:
// return PublicPersonalProfileGlobalizationUtil.globalize(
// "publicpersonalprofile.ui.nav.remove").localize();
return new Label( return new Label(
PublicPersonalProfileGlobalizationUtil.globalize( PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.nav.remove")); "publicpersonalprofile.ui.nav.remove"));
@ -202,51 +180,54 @@ public class PublicPersonalProfileNavigationTable extends Table
} }
@Override @Override
public Object getKeyAt(int columnIndex) { public Object getKeyAt(final int columnIndex) {
RelatedLink link = new RelatedLink(linkCollection.getDataObject()); final RelatedLink link = new RelatedLink(linkCollection.getDataObject());
return link.getID(); return link.getID();
} }
} }
private class EditCellRenderer private class EditCellRenderer
extends LockableImpl extends LockableImpl
implements TableCellRenderer { implements TableCellRenderer {
@Override public EditCellRenderer() {
public Component getComponent(Table table, super();
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int col) {
//com.arsdigita.cms.SecurityManager securityManager = Utilities.getSecurityManager(state);
// return new Label((String) value);
return (Component)value;
} }
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int col) {
return (Component) value;
}
} }
private class TargetCellRenderer private class TargetCellRenderer
extends LockableImpl extends LockableImpl
implements TableCellRenderer { implements TableCellRenderer {
public Component getComponent(Table table, public TargetCellRenderer() {
PageState state, super();
Object value, }
boolean isSelected,
Object key, public Component getComponent(final Table table,
int row, final PageState state,
int column) { final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
if (value == null) { if (value == null) {
return new Label(""); return new Label("");
} else { } else {
final ContentPage item = (ContentPage) value; final ContentPage item = (ContentPage) value;
com.arsdigita.cms.SecurityManager securityManager = Utilities. final com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(
getSecurityManager(state); state);
final boolean canEdit = securityManager.canAccess( final boolean canEdit = securityManager.canAccess(
state.getRequest(), state.getRequest(),
@ -254,10 +235,10 @@ public class PublicPersonalProfileNavigationTable extends Table
item); item);
if (canEdit) { if (canEdit) {
final ContentSection section = item.getContentSection();//CMS.getContext().getContentSection(); final ContentSection section = item.getContentSection();
ItemResolver resolver = section.getItemResolver(); final ItemResolver resolver = section.getItemResolver();
Link link = new Link(item.getTitle(), final Link link = new Link(item.getTitle(),
resolver.generateItemURL( resolver.generateItemURL(
state, item, section, item.getVersion())); state, item, section, item.getVersion()));
@ -267,68 +248,64 @@ public class PublicPersonalProfileNavigationTable extends Table
} }
} }
} }
} }
private class DeleteCellRenderer private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer {
extends LockableImpl
implements TableCellRenderer { public DeleteCellRenderer() {
//Nothing
}
@Override @Override
public Component getComponent(Table table, public Component getComponent(final Table table,
PageState state, final PageState state,
Object value, final Object value,
boolean isSelected, final boolean isSelected,
Object key, final Object key,
int row, final int row,
int col) { final int col) {
com.arsdigita.cms.SecurityManager securityManager = final com.arsdigita.cms.SecurityManager securityManager = CMS.getSecurityManager(state);
Utilities.getSecurityManager(state); final PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.
PublicPersonalProfile profile = (PublicPersonalProfile) itemModel.
getSelectedObject( getSelectedObject(
state); state);
boolean canDelete = securityManager.canAccess( final boolean canDelete = securityManager.canAccess(
state.getRequest(), state.getRequest(),
com.arsdigita.cms.SecurityManager.DELETE_ITEM, com.arsdigita.cms.SecurityManager.DELETE_ITEM,
profile); profile);
if (canDelete) { if (canDelete) {
ControlLink link = new ControlLink(value.toString()); final ControlLink link = new ControlLink((Component) value);
link.setConfirmation(PublicPersonalProfileGlobalizationUtil. link.setConfirmation(PublicPersonalProfileGlobalizationUtil.
globalize("publicpersonalprofile.ui.nav.remove.confirm") globalize("publicpersonalprofile.ui.nav.remove.confirm"));
);
return link; return link;
} else { } else {
// Label label = new Label(value.toString());
// return label;
return (Component) value; return (Component) value;
} }
} }
}
private class ActionListener implements TableActionListener {
public ActionListener() {
//Nothing
} }
@Override @Override
public void cellSelected(TableActionEvent event) { public void cellSelected(final TableActionEvent event) {
PageState state = event.getPageState(); final TableColumn column = getColumnModel().get(event.getColumn().intValue());
TableColumn column = getColumnModel().get(event.getColumn().intValue());
if (TABLE_COL_EDIT.equals(column.getHeaderKey().toString())) {
} else if (TABLE_COL_DEL.equals(column.getHeaderKey().toString())) {
final BigDecimal linkId = new BigDecimal(
event.getRowKey().toString());
RelatedLink link = new RelatedLink(linkId);
if (TABLE_COL_DEL.equals(column.getHeaderKey().toString())) {
final BigDecimal linkId = new BigDecimal(event.getRowKey().toString());
final RelatedLink link = new RelatedLink(linkId);
link.delete(); link.delete();
} }
} }
@Override @Override
public void headSelected(TableActionEvent event) { public void headSelected(final TableActionEvent event) {
//Nothing to do here. //Nothing to do here.
} }
} }
}