Fehlende Datei hinzufügt

git-svn-id: https://svn.libreccm.org/ccm/trunk@595 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2010-10-30 12:02:33 +00:00
parent cf98ba06b1
commit aa9c11f527
1 changed files with 231 additions and 0 deletions

View File

@ -0,0 +1,231 @@
/*
* Copyright (c) 2010 Jens Pelzetter,
* for the Center of Social Politics of the University of Bremen
*
* 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.cms.contenttypes.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.util.LockableImpl;
/**
*
* @author Jens Pelzetter
*/
public class GenericContactPersonSheet
extends Table
implements TableActionListener {
private final String TABLE_COL_EDIT = "table_col_edit";
private final String TABLE_COL_DEL = "table_col_del";
private ItemSelectionModel m_itemModel;
public GenericContactPersonSheet(ItemSelectionModel itemModel) {
super();
m_itemModel = itemModel;
setEmptyView(
new Label(ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.emptyPerson")));
TableColumnModel colModel = getColumnModel();
colModel.add(new TableColumn(
0,
ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.person").localize(),
TABLE_COL_EDIT));
colModel.add(new TableColumn(
1,
ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.delete_person").localize(),
TABLE_COL_DEL));
setModelBuilder(
new GenericContactPersonSheetModelBuilder(itemModel));
colModel.get(0).setCellRenderer(new EditCellRenderer());
colModel.get(1).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this);
}
private class GenericContactPersonSheetModelBuilder
extends LockableImpl
implements TableModelBuilder {
private ItemSelectionModel m_itemModel;
public GenericContactPersonSheetModelBuilder(
ItemSelectionModel itemModel) {
m_itemModel = itemModel;
}
@Override
public TableModel makeModel(Table table, PageState state) {
table.getRowSelectionModel().clearSelection(state);
GenericContact contact = (GenericContact) m_itemModel.
getSelectedObject(state);
return new GenericContactPersonSheetModel(table,
state,
contact);
}
}
private class GenericContactPersonSheetModel implements TableModel {
private Table m_table;
private GenericPerson m_person;
private boolean m_done;
public GenericContactPersonSheetModel(Table table,
PageState state,
GenericContact contact) {
m_table = table;
m_person = contact.getPerson();
if (m_person == null) {
m_done = false;
} else {
m_done = true;
}
}
public int getColumnCount() {
return m_table.getColumnModel().size();
}
public boolean nextRow() {
boolean ret;
if (m_done) {
ret = true;
m_done = false;
} else {
ret = false;
}
return ret;
}
public Object getElementAt(int columnIndex) {
switch (columnIndex) {
case 0:
return m_person.getFullName();
case 1:
return ContenttypesGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.delete_person").
localize();
default:
return null;
}
}
public Object getKeyAt(int columnIndex) {
return m_person.getID();
}
}
private class EditCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int column) {
Label label = new Label(value.toString());
return label;
}
}
private class DeleteCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int col) {
SecurityManager securityManager =
Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel.
getSelectedObject(
state);
boolean canEdit = securityManager.canAccess(
state.getRequest(),
SecurityManager.DELETE_ITEM,
contact);
if (canEdit) {
ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) ContenttypesGlobalizationUtil.
globalize(
"cms.contenttypes.ui.contact.person"
+ ".confirm_remove").
localize());
return link;
} else {
Label label = new Label(value.toString());
return label;
}
}
}
@Override
public void cellSelected(TableActionEvent event) {
PageState state = event.getPageState();
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
state);
TableColumn column = getColumnModel().get(event.getColumn().intValue());
if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) {
} else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
contact.unsetPerson();
}
}
@Override
public void headSelected(TableActionEvent event) {
//Nothing to do
}
}