diff --git a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl index 7b3abb720..a8132c0c7 100644 --- a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl @@ -31,23 +31,6 @@ object type GenericOrganizationalUnit extends ContentPage { reference key (cms_organizationalunits.organizationalunit_id); } -// Parent <-> child relation organizationalunits to build department structures etc. -association { - - GenericOrganizationalUnit[0..n] orgaunit_parent = join cms_organizationalunits.organizationalunit_id - to cms_organizationalunits_organizationalunit_map.orgaunit_children_id, - join cms_organizationalunits_organizationalunit_map.orgaunit_parent_id - to cms_organizationalunits.organizationalunit_id; - - GenericOrganizationalUnit[0..n] orgaunit_children = join cms_organizationalunits.organizationalunit_id - to cms_organizationalunits_organizationalunit_map.orgaunit_parent_id, - join cms_organizationalunits_organizationalunit_map.orgaunit_children_id - to cms_organizationalunits.organizationalunit_id; - - // Link attribute, allows it to customize the order which the childs will be shown. - Integer[0..1] orgaunit_children_order = cms_organizationalunits_organizationalunit_map.map_order INTEGER; -} - // Link for contact points. association { diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java index 67da8aff4..18abeb18a 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2010 Jens Pelzetter, for the Center of Social Politics of the University of Bremen + * 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 @@ -33,7 +34,6 @@ import java.math.BigDecimal; * An item of this content type can be linked with several other content types: * - Contact (0..n) * - Person (0..n) - * - GenericOrganizationalUnit (0..n) to build organizations structures. * * @author Jens Pelzetter * @version $Id$ @@ -45,9 +45,6 @@ public class GenericOrganizationalUnit extends ContentPage { public final static String CONTACTS = "contacts"; public final static String CONTACT_TYPE = "contact_type"; public final static String CONTACT_ORDER = "contact_order"; - public final static String ORGAUNIT_CHILDREN = "orgaunit_children"; - public final static String ORGAUNIT_CHILDREN_ORDER = - "orgaunit_children_order"; public final static String PERSONS = "persons"; public final static String ROLE = "role_name"; public final static String PERSON_ORDER = "person_order"; @@ -107,29 +104,6 @@ public class GenericOrganizationalUnit extends ContentPage { return !this.getContacts().isEmpty(); } - public GenericOrganizationalUnitChildrenCollection getOrgaUnitChildren() { - return new GenericOrganizationalUnitChildrenCollection((DataCollection) get( - ORGAUNIT_CHILDREN)); - } - - public void addOrgaUnitChildren(GenericOrganizationalUnit child) { - Assert.exists(child, GenericOrganizationalUnit.class); - - DataObject link = add(ORGAUNIT_CHILDREN, child); - - link.set(ORGAUNIT_CHILDREN_ORDER, Integer.valueOf((int) getOrgaUnitChildren(). - size())); - } - - public void removeOrgaUnitChildren(GenericOrganizationalUnit child) { - Assert.exists(child, GenericOrganizationalUnit.class); - remove(ORGAUNIT_CHILDREN, child); - } - - public boolean hasOrgaUnitChildren() { - return !this.getOrgaUnitChildren().isEmpty(); - } - public GenericOrganizationalUnitPersonCollection getPersons() { return new GenericOrganizationalUnitPersonCollection((DataCollection) get( PERSONS)); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitChildrenCollection.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitChildrenCollection.java deleted file mode 100644 index f27b4e24f..000000000 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitChildrenCollection.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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; - -import com.arsdigita.domain.DomainCollection; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.DataObject; -import org.apache.log4j.Logger; - -/** - * Collection class for the childs of a GenericOrganizationalUnit. - * - * @author Jens Pelzetter - */ -public class GenericOrganizationalUnitChildrenCollection - extends DomainCollection { - - public static final String ORDER = "link.orgaunit_children_order"; - public static final String CHILDREN_ORDER = "orgaunit_children_order"; - private final static Logger s_log = Logger.getLogger( - GenericOrganizationalUnitChildrenCollection.class); - - public GenericOrganizationalUnitChildrenCollection( - DataCollection dataCollection) { - super(dataCollection); - - m_dataCollection.addOrder(ORDER); - } - - /** - * Gets the value of the order attribute of the current association. - * - * @return Order value of the current item. - */ - public Integer getChildrenOrder() { - return (Integer) m_dataCollection.get(ORDER); - } - - /** - * Sets the order attribute for the current association. - * - * @param order The new value for the order. - */ - public void setChildrenOrder(Integer order) { - DataObject link = (DataObject) this.get("link"); - - link.set(CHILDREN_ORDER, order); - } - - /** - * Swaps the item {@code child} with the next one in the collection. - * - * @param child The child to swap with the next one. - * @throws IllegalArgumentException Thrown if the child object provided is - * not part of this collection, or if the child is the last one in the - * collection. - */ - public void swapWithNext(GenericOrganizationalUnit child) { - int currentPos = 0; - int currentIndex = 0; - int nextIndex = 0; - - s_log.debug("Searching child..."); - this.rewind(); - while (this.next()) { - currentPos = this.getPosition(); - currentIndex = this.getChildrenOrder(); - s_log.debug(String.format("Position: %d(%d)/%d", currentPos, - currentIndex, this.size())); - s_log.debug(String.format("getChildrenOrder(): %d", - getChildrenOrder())); - if (this.getOrgaUnitChild().equals(child)) { - break; - } - } - - if (currentPos == 0) { - throw new IllegalArgumentException( - String.format( - "The provided organizational unit is not " - + "part of this collection.")); - } - - if (this.next()) { - nextIndex = this.getChildrenOrder(); - } else { - throw new IllegalArgumentException( - "The provided organizational unit is the last " - + "in the collection, so there is no next object " - + "to swap with."); - } - - this.rewind(); - - while (this.getPosition() != currentPos) { - this.next(); - } - - this.setChildrenOrder(nextIndex); - this.next(); - this.setChildrenOrder(currentIndex); - this.rewind(); - } - - /** - * Swaps the item {@code child} with the previous one in the collection. - * - * @param child The child to swap with the previous one. - * @throws IllegalArgumentException Thrown if the child object provided is - * not part of this collection, or if the child is the first one in the - * collection. - */ - public void swapWithPrevious(GenericOrganizationalUnit child) { - int previousPos = 0; - int previousIndex = 0; - int currentPos = 0; - int currentIndex = 0; - - s_log.debug("Searching child..."); - this.rewind(); - while (this.next()) { - currentPos = this.getPosition(); - currentIndex = this.getChildrenOrder(); - s_log.debug(String.format("Position: %d(%d)/%d", currentPos, - currentIndex, this.size())); - s_log.debug(String.format("getChildrenOrder(): %d", - getChildrenOrder())); - if (this.getOrgaUnitChild().equals(child)) { - break; - } - - previousPos = currentPos; - previousIndex = currentIndex; - } - - if (currentPos == 0) { - throw new IllegalArgumentException( - String.format( - "The provided organizational unit is not " - + "part of this collection.")); - } - - if (previousPos == 0) { - throw new IllegalArgumentException( - String.format( - "The provided organizational unit is the first one in this " - + "collection, so there is no previous one to switch " - + "with.")); - } - - this.rewind(); - while (this.getPosition() != previousPos) { - this.next(); - } - - this.setChildrenOrder(currentIndex); - this.next(); - this.setChildrenOrder(previousIndex); - this.rewind(); - } - - /** - * Retrieves the current child. - * - * @return The GenericOrganizationalUnit at the cursors current position. - */ - public GenericOrganizationalUnit getOrgaUnitChild() { - return new GenericOrganizationalUnit( - m_dataCollection.getDataObject()); - } -} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildAddForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildAddForm.java deleted file mode 100644 index 1c8fd6850..000000000 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildAddForm.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * 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.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; -import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; -import com.arsdigita.cms.ui.ItemSearchWidget; -import com.arsdigita.cms.ui.authoring.BasicItemForm; -import org.apache.log4j.Logger; - -/** - * Form for adding a child to an organization. To change the type of childs - * allowed, overwrite the {@link getChildDataObjectType()} method. - * - * @author Jens Pelzetter - */ -public class GenericOrganizationalUnitChildAddForm extends BasicItemForm { - - private static final Logger s_log = Logger.getLogger( - GenericOrganizationalUnitChildAddForm.class); - private GenericOrganizationalUnitChildrenPropertiesStep m_step; - private ItemSearchWidget m_itemSearch; - private SaveCancelSection m_saveCancelSection; - private final String ITEM_SEARCH = "orgaunitChild"; - private ItemSelectionModel m_itemModel; - - public GenericOrganizationalUnitChildAddForm(ItemSelectionModel itemModel) { - this("ChildAddForm", itemModel); - } - - public GenericOrganizationalUnitChildAddForm(String formName, - ItemSelectionModel itemModel) { - super(formName, itemModel); - } - - @Override - protected void addWidgets() { - add(new Label( - (String) ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.select_child").localize())); - - this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType. - findByAssociatedObjectType( - getChildDataObjectType())); - add(this.m_itemSearch); - - } - - @Override - public void init(FormSectionEvent fse) throws FormProcessException { - FormData data = fse.getFormData(); - PageState state = fse.getPageState(); - - setVisible(state, true); - } - - @Override - public void process(FormSectionEvent fse) throws FormProcessException { - FormData data = fse.getFormData(); - PageState state = fse.getPageState(); - GenericOrganizationalUnit parent = (GenericOrganizationalUnit) getItemSelectionModel(). - getSelectedObject(state); - - if (!(this.getSaveCancelSection().getCancelButton().isSelected(state))) { - parent.addOrgaUnitChildren((GenericOrganizationalUnit) data.get( - ITEM_SEARCH)); - } - - init(fse); - } - - /** - * - * @return The BASE_DATA_OBJECT_TYPE of the childs allowed. - */ - protected String getChildDataObjectType() { - return GenericOrganizationalUnit.BASE_DATA_OBJECT_TYPE; - } -} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java deleted file mode 100644 index cb02e2189..000000000 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java +++ /dev/null @@ -1,346 +0,0 @@ -/* - * 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.bebop.util.GlobalizationUtil; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; -import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitChildrenCollection; -import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; -import com.arsdigita.cms.dispatcher.Utilities; -import com.arsdigita.util.LockableImpl; -import java.math.BigDecimal; -import org.apache.log4j.Logger; - -/** - * Table for showing the childs of an organization. - * - * @author Jens Pelzetter - */ -public class GenericOrganizationalUnitChildTable extends Table implements - TableActionListener { - - private final String TABLE_COL_EDIT = "table_col_edit"; - private final String TABLE_COL_DEL = "table_col_del"; - private final String TABLE_COL_UP = "table_col_up"; - private final String TABLE_COL_DOWN = "table_col_down"; - private ItemSelectionModel m_itemModel; - private static final Logger s_log = - Logger.getLogger( - GenericOrganizationalUnitChildTable.class); - - public GenericOrganizationalUnitChildTable( - final ItemSelectionModel itemModel) { - super(); - this.m_itemModel = itemModel; - - setEmptyView(new Label(ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.childs.none"))); - TableColumnModel tabModel = getColumnModel(); - - /*tabModel.add(new TableColumn( - 0, - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.child.order").localize(), - TABLE_COL_EDIT));*/ - tabModel.add(new TableColumn( - 0, - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.child.name").localize(), - TABLE_COL_EDIT)); - tabModel.add(new TableColumn( - 1, - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.child.action").localize(), - TABLE_COL_DEL)); - tabModel.add(new TableColumn( - 2, - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.child.up").localize(), - TABLE_COL_UP)); - tabModel.add(new TableColumn( - 3, - ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.child.down").localize(), - TABLE_COL_DOWN)); - - - setModelBuilder(new GenericOrganizationalUnitChildTableModelBuilder( - itemModel)); - - tabModel.get(0).setCellRenderer(new EditCellRenderer()); - tabModel.get(1).setCellRenderer(new DeleteCellRenderer()); - tabModel.get(2).setCellRenderer(new UpCellRenderer()); - tabModel.get(3).setCellRenderer(new DownCellRenderer()); - - addTableActionListener(this); - - } - - private class GenericOrganizationalUnitChildTableModelBuilder extends LockableImpl - implements TableModelBuilder { - - private ItemSelectionModel m_itemModel; - - public GenericOrganizationalUnitChildTableModelBuilder( - ItemSelectionModel itemModel) { - m_itemModel = itemModel; - } - - @Override - public TableModel makeModel(Table table, PageState state) { - table.getRowSelectionModel().clearSelection(state); - GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - return new GenericOrganizationalUnitChildTableModel(table, state, - orgaunit); - } - } - - private class GenericOrganizationalUnitChildTableModel implements TableModel { - - final private int MAX_DESC_LENGTH = 25; - private Table m_table; - private GenericOrganizationalUnitChildrenCollection m_childCollection; - private GenericOrganizationalUnit m_child; - - private GenericOrganizationalUnitChildTableModel(Table table, - PageState state, - GenericOrganizationalUnit orgaunit) { - m_table = table; - m_childCollection = orgaunit.getOrgaUnitChildren(); - } - - @Override - public int getColumnCount() { - return m_table.getColumnModel().size(); - } - - @Override - public boolean nextRow() { - boolean ret; - - if ((m_childCollection != null) && m_childCollection.next()) { - m_child = m_childCollection.getOrgaUnitChild(); - ret = true; - } else { - ret = false; - } - - return ret; - } - - @Override - public Object getElementAt(int colIndex) { - switch (colIndex) { - /*case 0: - return m_childCollection.getChildrenOrder();*/ - case 0: - return m_child.getName(); - case 1: - return GlobalizationUtil.globalize("cms.ui.delete").localize(); - default: - return null; - } - } - - @Override - public Object getKeyAt(int colIndex) { - return m_child.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 col) { - com.arsdigita.cms.SecurityManager securityManager = Utilities. - getSecurityManager(state); - GenericOrganizationalUnit orgaunit = - (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - - boolean canEdit = securityManager.canAccess( - state.getRequest(), - com.arsdigita.cms.SecurityManager.EDIT_ITEM, - orgaunit); - if (canEdit) { - ControlLink link = new ControlLink(value.toString()); - return link; - } else { - return new Label(value.toString()); - } - } - } - - 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) { - com.arsdigita.cms.SecurityManager securityManager = Utilities. - getSecurityManager(state); - GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - - boolean canEdit = securityManager.canAccess( - state.getRequest(), - com.arsdigita.cms.SecurityManager.DELETE_ITEM, - orgaunit); - if (canEdit) { - ControlLink link = new ControlLink(value.toString()); - link.setConfirmation((String) ContenttypesGlobalizationUtil. - globalize( - "cms.contenttypes.ui.genericorgaunit.confirm_delete"). - localize()); - return link; - } else { - return new Label(value.toString()); - } - } - } - - private class UpCellRenderer extends LockableImpl implements - TableCellRenderer { - - @Override - public Component getComponent( - Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int col) { - /*com.arsdigita.cms.SecurityManager securityManager = Utilities. - getSecurityManager(state); - GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state);*/ - - /*GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - GenericOrganizationalUnitChildrenCollection children = - orgaunit.getOrgaUnitChildren();*/ - - s_log.debug(String.format("row = %d", row)); - //s_log.debug(String.format("children.size = %d", children.size())); - - if (0 == row) { - s_log.debug("row is first row in table, don't show 'up'-link..."); - return new Label(""); - } else { - ControlLink link = new ControlLink("up"); - return link; - } - } - } - - private class DownCellRenderer extends LockableImpl implements - TableCellRenderer { - - @Override - public Component getComponent( - Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int col) { - /*com.arsdigita.cms.SecurityManager securityManager = Utilities. - getSecurityManager(state); - GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state);*/ - - GenericOrganizationalUnit orgaunit = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - GenericOrganizationalUnitChildrenCollection children = - orgaunit. - getOrgaUnitChildren(); - - - if ((children.size() - 1) == row) { - s_log.debug( - "Row is last row of table, don't show 'down'-link..."); - return new Label(""); - } else { - ControlLink link = new ControlLink("down"); - return link; - } - } - } - - @Override - public void cellSelected(TableActionEvent event) { - PageState state = event.getPageState(); - - GenericOrganizationalUnit child = new GenericOrganizationalUnit(new BigDecimal(event. - getRowKey().toString())); - - GenericOrganizationalUnit parent = (GenericOrganizationalUnit) m_itemModel. - getSelectedObject(state); - - GenericOrganizationalUnitChildrenCollection children = - parent.getOrgaUnitChildren(); - - TableColumn col = getColumnModel().get(event.getColumn().intValue()); - - if (col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { - } else if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) { - parent.removeOrgaUnitChildren(child); - } else if (col.getHeaderKey().equals(TABLE_COL_UP)) { - children.swapWithPrevious(child); - } else if (col.getHeaderKey().equals(TABLE_COL_DOWN)) { - children.swapWithNext(child); - } - } - - @Override - public void headSelected(TableActionEvent event) { - throw new UnsupportedOperationException("Not supported yet."); - } -} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java deleted file mode 100644 index 57880d68f..000000000 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; - -/** - * Step for editing the childs of an organization (other organizations). - * - * @author Jens Pelzetter - */ -public class GenericOrganizationalUnitChildrenPropertiesStep extends SimpleEditStep { - - private static String ADD_CHILD_SHEET_NAME = "addChild"; - - public GenericOrganizationalUnitChildrenPropertiesStep( - ItemSelectionModel itemModel, - AuthoringKitWizard parent) { - this(itemModel, parent, null); - } - - public GenericOrganizationalUnitChildrenPropertiesStep( - ItemSelectionModel itemModel, - AuthoringKitWizard parent, - String prefix) { - super(itemModel, parent, prefix); - - BasicItemForm addChildSheet = new GenericOrganizationalUnitChildAddForm( - itemModel); - add(ADD_CHILD_SHEET_NAME, - (String) ContenttypesGlobalizationUtil.globalize( - "cms.contenttypes.ui.genericorgaunit.add_child").localize(), - new WorkflowLockedComponentAccess(addChildSheet, itemModel), - addChildSheet.getSaveCancelSection().getCancelButton()); - - GenericOrganizationalUnitChildTable childrenTable = - new GenericOrganizationalUnitChildTable(itemModel); - setDisplayComponent(childrenTable); - } -} diff --git a/ccm-core/src/com/arsdigita/kernel/permissions/PrivilegeDescriptor.java b/ccm-core/src/com/arsdigita/kernel/permissions/PrivilegeDescriptor.java index 0b17d85d5..195b80bfa 100755 --- a/ccm-core/src/com/arsdigita/kernel/permissions/PrivilegeDescriptor.java +++ b/ccm-core/src/com/arsdigita/kernel/permissions/PrivilegeDescriptor.java @@ -109,9 +109,11 @@ public class PrivilegeDescriptor { addChildPrivilege(ADMIN_NAME, name); s_log.warn(String.format("Creating privilege %s...", name)); // Constructor PrivilegeDescriptor is deprecated and should be - // replace the class method get(name) - //PrivilegeDescriptor desc = new PrivilegeDescriptor(name); - PrivilegeDescriptor desc = get(name); + // replaced by the class method get(name), + // but this does not work under all circumstances. Further + // investigation of this issue is neccessary. + PrivilegeDescriptor desc = new PrivilegeDescriptor(name); + //PrivilegeDescriptor desc = get(name); put(desc); return desc; } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/CollectedVolumeArticlesTable.java b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/CollectedVolumeArticlesTable.java index b0b79b05a..e71140ef2 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/CollectedVolumeArticlesTable.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/CollectedVolumeArticlesTable.java @@ -184,7 +184,6 @@ public class CollectedVolumeArticlesTable } else { Label label = new Label(value.toString()); return label; - } } } diff --git a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/MonographPropertiesStep.java b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/MonographPropertiesStep.java index 9ff479bea..ad7f8d434 100644 --- a/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/MonographPropertiesStep.java +++ b/ccm-sci-publications/src/com/arsdigita/cms/contenttypes/ui/MonographPropertiesStep.java @@ -3,7 +3,6 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Label; import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.Monograph; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.SimpleEditStep; diff --git a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl index 357944cf5..12115e288 100644 --- a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl +++ b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciDepartment.pdl @@ -4,7 +4,34 @@ import com.arsdigita.kernel.ACSObject; import com.arsdigita.cms.*; object type SciDepartment extends GenericOrganizationalUnit { - String[0..1] description = ct_scidepartments.description; + String[0..1] departmentDescription = ct_scidepartments.description; - reference key ( ct_scidepartments.organization_id ); + reference key ( ct_scidepartments.department_id ); } + +association { + SciDepartment[0..1] department = join ct_scidepartments.department_id + to ct_scidepartments_subdepartments_map.department_id, + join ct_scidepartments_subdepartments_map.subdepartment_id + to ct_scidepartments.department_id; + SciDepartment[0..n] subDepartments = join ct_scidepartments.department_id + to ct_scidepartments_subdepartments_map.subdepartment_id, + join ct_scidepartments_subdepartments_map.department_id + to ct_scidepartments.department_id; + + Integer[0..1] subDepartmentOrder = ct_scidepartments_subdepartments_map.subdepartments_order INTEGER; +} + +association { + SciDepartment[0..1] department = join ct_scidepartments.department_id + to ct_scidepartments_projects_map.department_id, + join ct_scidepartments_projects_map.project_id, + to ct_sciprojects.project_id; + + SciProject[0..n] projects = join ct_sciprojects.project_id + to ct_scidepartments_projects_map.project_id, + join ct_scidepartments_projects_map.department_id + to ct_scidepartments.department_id; + + Integer[0..1] projectOrder = ct_scidepartments_projects_map.projectorder INTEGER; +} \ No newline at end of file diff --git a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciOrganization.pdl b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciOrganization.pdl index 664f31eb3..1569a7531 100644 --- a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciOrganization.pdl +++ b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciOrganization.pdl @@ -4,7 +4,37 @@ import com.arsdigita.kernel.ACSObject; import com.arsdigita.cms.*; object type SciOrganization extends GenericOrganizationalUnit { - String[0..1] description = ct_sciorganizations.description; + String[0..1] organizationDescription = ct_sciorganizations.description; reference key ( ct_sciorganizations.organization_id ); } + +association { + SciOrganization[0..1] organization = join ct_sciorganizations.organization_id + to ct_sciorganizations_departments_map.organization_id, + join ct_sciorganizations_departments_map.department_id + to ct_scidepartments.department_id; + + SciDepartment[0..n] departments = join ct_scidepartments.department_id + to ct_sciorganizations_departments_map.department_id, + join ct_sciorganizations_departments_map.organization_id + to ct_sciorganizations.organization_id; + + Integer[0..1] departmentOrder = ct_sciorganizations_departments_map.department_order INTEGER; +} + +association { + SciOrganization[0..1] organization = join ct_sciorganizations.organization_id + to ct_sciorganizations_projects_map.organization_id, + join ct_sciorganizations_projects_map.project_id + to ct_sciprojects.project_id; + + SciProject[0..n] projects = join ct_sciprojects.project_id + to ct_sciorganizations_projects_map.project_id, + join ct_sciorganizations_projects_map.organization_id + to ct_sciorganizations.organization_id; + + Integer[0..1] projectOrder = ct_sciorganizations_projects_map.project_order INTEGER; +} + + diff --git a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciProject.pdl b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciProject.pdl index 64b0a3be7..fe04755a6 100644 --- a/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciProject.pdl +++ b/ccm-sci-types-organization/pdl/com/arsdigita/content-types/SciProject.pdl @@ -7,8 +7,23 @@ object type SciProject extends GenericOrganizationalUnit { Date[0..1] projectbegin = ct_sciprojects.projectbegin DATE; Date[0..1] projectend = ct_sciprojects.projectend DATE; - String[0..1] description = ct_sciprojects.description VARCHAR(4096); + String[0..1] projectDescription = ct_sciprojects.description VARCHAR(4096); String[0..1] funding = ct_sciprojects.funding VARCHAR(2048); - reference key ( ct_sciprojects.organization_id ); + reference key ( ct_sciprojects.project_id ); } + +association { + SciProject[0..1] project = join ct_sciprojects.project_id + to ct_sciprojects_subprojects_map.project_id, + join ct_sciprojects_subprojects_map.subproject_id + to ct_sciprojects.project_id; + + SciProject[0..n] subProjects = join ct_sciprojects.project_id + to ct_sciprojects_subprojects_map.subproject_id, + join ct_sciprojects_subprojects_map.project_id + to ct_sciprojects.project_id; + + Integer[0..1] subProjectOrder = ct_sciprojects_subprojects_map.subprojectorder INTEGER; + +} \ No newline at end of file diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartment.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartment.java index 12bd4a803..0a931d11a 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartment.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartment.java @@ -1,8 +1,10 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; import java.math.BigDecimal; /** @@ -11,7 +13,11 @@ import java.math.BigDecimal; */ public class SciDepartment extends GenericOrganizationalUnit { - public static final String DESCRIPTION = "description"; + public static final String DEPARTMENT_DESCRIPTION = "departmentDescription"; + public static final String SUBDEPARTMENTS = "subDepartments"; + public static final String SUBDEPARTMENT_ORDER = "subDepartmentOrder"; + public static final String PROJECTS = "projects"; + public static final String PROJECT_ORDER = "projectOrder"; public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.SciDepartment"; @@ -35,11 +41,59 @@ public class SciDepartment extends GenericOrganizationalUnit { super(type); } - public String getDescription() { - return (String) get(DESCRIPTION); + public String getDepartmentDescription() { + return (String) get(DEPARTMENT_DESCRIPTION); } - public void setDescription(String description) { - set(DESCRIPTION, description); + public void setDepartmentDescription(String description) { + set(DEPARTMENT_DESCRIPTION, description); + } + + public SciDepartmentSubDepartmentsCollection getSubDepartments() { + return new SciDepartmentSubDepartmentsCollection( + (DataCollection) get(SUBDEPARTMENTS)); + } + + public void addSubDepartment(SciDepartment subDepartment) { + Assert.exists(subDepartment, SciDepartment.class); + + DataObject link = add(SUBDEPARTMENTS, subDepartment); + + link.set(SUBDEPARTMENT_ORDER, Integer.valueOf((int) getSubDepartments(). + size())); + } + + public void removeSubDepartment(SciDepartment subDepartment) { + Assert.exists(subDepartment, SciDepartment.class); + + remove(SUBDEPARTMENTS, subDepartment); + } + + public boolean hasSubDepartments() { + return !this.getSubDepartments().isEmpty(); + } + + public SciDepartmentProjectsCollection getProjects() { + return new SciDepartmentProjectsCollection( + (DataCollection) get(PROJECTS)); + } + + public void addProject(SciProject project) { + Assert.exists(project, SciProject.class); + + DataObject link = add(PROJECTS, project); + + link.set(PROJECT_ORDER, + Integer.valueOf((int) getProjects().size())); + } + + public void removeProject(SciProject project) { + Assert.exists(project, SciProject.class); + + remove(PROJECTS, project); + } + + public boolean hasProjects() { + return !this.getProjects().isEmpty(); } } diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentProjectsCollection.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentProjectsCollection.java new file mode 100644 index 000000000..34917eed3 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentProjectsCollection.java @@ -0,0 +1,154 @@ +/* + * 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; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentProjectsCollection extends DomainCollection { + + public String ORDER = "projectOrder"; + public String LINKORDER = "link.projectOrder"; + private static final Logger s_log = + Logger.getLogger(SciDepartmentProjectsCollection.class); + + public SciDepartmentProjectsCollection(DataCollection dataCollection) { + super(dataCollection); + + m_dataCollection.addOrder(LINKORDER); + } + + public Integer getProjectOrder() { + return (Integer) m_dataCollection.get(LINKORDER); + } + + public void setProjectOrder(Integer order) { + DataObject link = (DataObject) this.get("link"); + + link.set(ORDER, order); + } + + public void swapWithNext(SciProject project) { + int currentPosition = 0; + int currentIndex = 0; + int nextIndex = 0; + + s_log.debug("Searching project..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getProjectOrder(): %d", + getProjectOrder())); + if (this.getProject().equals(project)) { + break; + } + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is not " + + "part of this collection.")); + } + + if (this.next()) { + nextIndex = this.getProjectOrder(); + } else { + throw new IllegalArgumentException( + "The provided project is the last " + + "in the collection, so there is no next object " + + "to swap with."); + } + + this.rewind(); + + while (this.getPosition() != currentPosition) { + this.next(); + } + + this.setProjectOrder(nextIndex); + this.next(); + this.setProjectOrder(currentIndex); + this.rewind(); + } + + public void swapWithPrevious(SciProject project) { + int previousPosition = 0; + int previousIndex = 0; + int currentPosition = 0; + int currentIndex = 0; + + s_log.debug("Searching project..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getProjectOrder(): %d", + getProjectOrder())); + if (this.getProject().equals(project)) { + break; + } + + previousPosition = currentPosition; + previousIndex = currentIndex; + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is not " + + "part of this collection.")); + } + + if (previousPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is the first one in this " + + "collection, so there is no previous one to switch " + + "with.")); + } + + this.rewind(); + while (this.getPosition() != previousPosition) { + this.next(); + } + + this.setProjectOrder(currentIndex); + this.next(); + this.setProjectOrder(previousIndex); + this.rewind(); + } + + public SciProject getProject() { + return new SciProject(m_dataCollection.getDataObject()); + } +} + diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentSubDepartmentsCollection.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentSubDepartmentsCollection.java new file mode 100644 index 000000000..ca922d941 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciDepartmentSubDepartmentsCollection.java @@ -0,0 +1,153 @@ +/* + * 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; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentSubDepartmentsCollection extends DomainCollection { + + public String ORDER = "subDepartmentOrder"; + public String LINKORDER = "link.subDepartmentOrder"; + private static final Logger s_log = + Logger.getLogger(SciDepartmentSubDepartmentsCollection.class); + + public SciDepartmentSubDepartmentsCollection(DataCollection dataCollection) { + super(dataCollection); + + m_dataCollection.addOrder(LINKORDER); + } + + public Integer getSubDepartmentOrder() { + return (Integer) m_dataCollection.get(LINKORDER); + } + + public void setSubDepartmentOrder(Integer order) { + DataObject link = (DataObject) this.get("link"); + + link.set(ORDER, order); + } + + public void swapWithNext(SciDepartment department) { + int currentPosition = 0; + int currentIndex = 0; + int nextIndex = 0; + + s_log.debug("Searching department..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getSubDepartmentOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getDepartmentOrder(): %d", + getSubDepartmentOrder())); + if (this.getSubDepartment().equals(department)) { + break; + } + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is not " + + "part of this collection.")); + } + + if (this.next()) { + nextIndex = this.getSubDepartmentOrder(); + } else { + throw new IllegalArgumentException( + "The provided department is the last " + + "in the collection, so there is no next object " + + "to swap with."); + } + + this.rewind(); + + while (this.getPosition() != currentPosition) { + this.next(); + } + + this.setSubDepartmentOrder(nextIndex); + this.next(); + this.setSubDepartmentOrder(currentIndex); + this.rewind(); + } + + public void swapWithPrevious(SciDepartment department) { + int previousPosition = 0; + int previousIndex = 0; + int currentPosition = 0; + int currentIndex = 0; + + s_log.debug("Searching department..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getSubDepartmentOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getDepartmentOrder(): %d", + getSubDepartmentOrder())); + if (this.getSubDepartment().equals(department)) { + break; + } + + previousPosition = currentPosition; + previousIndex = currentIndex; + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is not " + + "part of this collection.")); + } + + if (previousPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is the first one in this " + + "collection, so there is no previous one to switch " + + "with.")); + } + + this.rewind(); + while (this.getPosition() != previousPosition) { + this.next(); + } + + this.setSubDepartmentOrder(currentIndex); + this.next(); + this.setSubDepartmentOrder(previousIndex); + this.rewind(); + } + + public SciDepartment getSubDepartment() { + return new SciDepartment(m_dataCollection.getDataObject()); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java index d63e05493..377a8b11e 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganization.java @@ -1,8 +1,10 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; import java.math.BigDecimal; /** @@ -11,9 +13,14 @@ import java.math.BigDecimal; */ public class SciOrganization extends GenericOrganizationalUnit { - public static final String DESCRIPTION = "description"; + public static final String ORGANIZATION_DESCRIPTION = + "organizationDescription"; + public static final String DEPARTMENTS = "departments"; + public static final String DEPARTMENT_ORDER = "departmentOrder"; + public static final String PROJECTS ="projects"; + public static final String PROJECT_ORDER = "projectOrder"; public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.contenttypes.SciOrganization"; + "com.arsdigita.cms.contenttypes.SciOrganization"; public SciOrganization() { this(BASE_DATA_OBJECT_TYPE); @@ -35,11 +42,58 @@ public class SciOrganization extends GenericOrganizationalUnit { super(type); } - public String getDescription() { - return (String) get(DESCRIPTION); + public String getOrganizationDescription() { + return (String) get(ORGANIZATION_DESCRIPTION); } - public void setDescription(String description) { - set(DESCRIPTION, description); + public void setOrganizationDescription(String description) { + set(ORGANIZATION_DESCRIPTION, description); + } + + public SciOrganizationDepartmentsCollection getDepartments() { + return new SciOrganizationDepartmentsCollection( + (DataCollection) get(DEPARTMENTS)); + } + + public void addDepartment(SciDepartment department) { + Assert.exists(department, SciDepartment.class); + + DataObject link = add(DEPARTMENTS, department); + + link.set(DEPARTMENT_ORDER, + Integer.valueOf((int) getDepartments().size())); + } + + public void removeDepartment(SciDepartment department) { + Assert.exists(department, SciDepartment.class); + + remove(DEPARTMENTS, department); + } + + public boolean hasDepartments() { + return !this.getDepartments().isEmpty(); + } + + public SciOrganizationProjectsCollection getProjects() { + return new SciOrganizationProjectsCollection( + (DataCollection) get(PROJECTS)); + } + + public void addProject(SciProject project) { + Assert.exists(project, SciProject.class); + + DataObject link = add(PROJECTS, project); + + link.set(PROJECT_ORDER, Integer.valueOf((int) getProjects().size())); + } + + public void removeProject(SciProject project) { + Assert.exists(project, SciProject.class); + + remove(PROJECTS, project); + } + + public boolean hasProjects() { + return !this.getProjects().isEmpty(); } } diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationDepartmentsCollection.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationDepartmentsCollection.java new file mode 100644 index 000000000..e8ad4d32d --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationDepartmentsCollection.java @@ -0,0 +1,153 @@ +/* + * 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; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationDepartmentsCollection extends DomainCollection { + + public String ORDER = "departmentOrder"; + public String LINKORDER = "link.departmentOrder"; + private static final Logger s_log = + Logger.getLogger(SciOrganizationDepartmentsCollection.class); + + public SciOrganizationDepartmentsCollection(DataCollection dataCollection) { + super(dataCollection); + + m_dataCollection.addOrder(LINKORDER); + } + + public Integer getDepartmentOrder() { + return (Integer) m_dataCollection.get(LINKORDER); + } + + public void setDepartmentOrder(Integer order) { + DataObject link = (DataObject) this.get("link"); + + link.set(ORDER, order); + } + + public void swapWithNext(SciDepartment department) { + int currentPosition = 0; + int currentIndex = 0; + int nextIndex = 0; + + s_log.debug("Searching department..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getDepartmentOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getDepartmentOrder(): %d", + getDepartmentOrder())); + if (this.getDepartment().equals(department)) { + break; + } + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is not " + + "part of this collection.")); + } + + if (this.next()) { + nextIndex = this.getDepartmentOrder(); + } else { + throw new IllegalArgumentException( + "The provided department is the last " + + "in the collection, so there is no next object " + + "to swap with."); + } + + this.rewind(); + + while (this.getPosition() != currentPosition) { + this.next(); + } + + this.setDepartmentOrder(nextIndex); + this.next(); + this.setDepartmentOrder(currentIndex); + this.rewind(); + } + + public void swapWithPrevious(SciDepartment department) { + int previousPosition = 0; + int previousIndex = 0; + int currentPosition = 0; + int currentIndex = 0; + + s_log.debug("Searching department..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getDepartmentOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getDepartmentOrder(): %d", + getDepartmentOrder())); + if (this.getDepartment().equals(department)) { + break; + } + + previousPosition = currentPosition; + previousIndex = currentIndex; + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is not " + + "part of this collection.")); + } + + if (previousPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided department is the first one in this " + + "collection, so there is no previous one to switch " + + "with.")); + } + + this.rewind(); + while (this.getPosition() != previousPosition) { + this.next(); + } + + this.setDepartmentOrder(currentIndex); + this.next(); + this.setDepartmentOrder(previousIndex); + this.rewind(); + } + + public SciDepartment getDepartment() { + return new SciDepartment(m_dataCollection.getDataObject()); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationProjectsCollection.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationProjectsCollection.java new file mode 100644 index 000000000..fd61e154d --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciOrganizationProjectsCollection.java @@ -0,0 +1,154 @@ +/* + * 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; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationProjectsCollection extends DomainCollection { + + public String ORDER = "projectOrder"; + public String LINKORDER = "link.projectOrder"; + private static final Logger s_log = + Logger.getLogger(SciOrganizationProjectsCollection.class); + + public SciOrganizationProjectsCollection(DataCollection dataCollection) { + super(dataCollection); + + m_dataCollection.addOrder(LINKORDER); + } + + public Integer getProjectOrder() { + return (Integer) m_dataCollection.get(LINKORDER); + } + + public void setProjectOrder(Integer order) { + DataObject link = (DataObject) this.get("link"); + + link.set(ORDER, order); + } + + public void swapWithNext(SciProject project) { + int currentPosition = 0; + int currentIndex = 0; + int nextIndex = 0; + + s_log.debug("Searching project..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getProjectOrder(): %d", + getProjectOrder())); + if (this.getProject().equals(project)) { + break; + } + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is not " + + "part of this collection.")); + } + + if (this.next()) { + nextIndex = this.getProjectOrder(); + } else { + throw new IllegalArgumentException( + "The provided project is the last " + + "in the collection, so there is no next object " + + "to swap with."); + } + + this.rewind(); + + while (this.getPosition() != currentPosition) { + this.next(); + } + + this.setProjectOrder(nextIndex); + this.next(); + this.setProjectOrder(currentIndex); + this.rewind(); + } + + public void swapWithPrevious(SciProject project) { + int previousPosition = 0; + int previousIndex = 0; + int currentPosition = 0; + int currentIndex = 0; + + s_log.debug("Searching project..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getProjectOrder(): %d", + getProjectOrder())); + if (this.getProject().equals(project)) { + break; + } + + previousPosition = currentPosition; + previousIndex = currentIndex; + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is not " + + "part of this collection.")); + } + + if (previousPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided project is the first one in this " + + "collection, so there is no previous one to switch " + + "with.")); + } + + this.rewind(); + while (this.getPosition() != previousPosition) { + this.next(); + } + + this.setProjectOrder(currentIndex); + this.next(); + this.setProjectOrder(previousIndex); + this.rewind(); + } + + public SciProject getProject() { + return new SciProject(m_dataCollection.getDataObject()); + } +} + diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProject.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProject.java index 911d60f1f..552d551cc 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProject.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProject.java @@ -1,8 +1,29 @@ +/* + * 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; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; import java.math.BigDecimal; import java.util.Date; @@ -10,20 +31,22 @@ import java.util.Date; * * @author Jens Pelzetter */ -public class SciProject extends GenericOrganizationalUnit{ +public class SciProject extends GenericOrganizationalUnit { public static final String BEGIN = "projectbegin"; public static final String END = "projectend"; - public static final String DESCRIPTION = "description"; + public static final String PROJECT_DESCRIPTION = "projectDescription"; public static final String FUNDING = "funding"; - public static final String BASE_DATA_OBJECT_TYPE = - "com.arsdigita.cms.contenttypes.SciProject"; - + public static final String SUBPROJECTS = "subProjects"; + public static final String SUBPROJECT_ORDER = "subProjectOrder"; + public static final String BASE_DATA_OBJECT_TYPE = + "com.arsdigita.cms.contenttypes.SciProject"; + public SciProject() { super(BASE_DATA_OBJECT_TYPE); } - public SciProject(BigDecimal id ) throws DataObjectNotFoundException{ + public SciProject(BigDecimal id) throws DataObjectNotFoundException { this(new OID(BASE_DATA_OBJECT_TYPE, id)); } @@ -55,12 +78,12 @@ public class SciProject extends GenericOrganizationalUnit{ set(END, end); } - public String getDescription() { - return (String) get(DESCRIPTION); + public String getProjectDescription() { + return (String) get(PROJECT_DESCRIPTION); } - public void setDescription(String description) { - set(DESCRIPTION, description); + public void setProjectDescription(String description) { + set(PROJECT_DESCRIPTION, description); } public String getFunding() { @@ -71,4 +94,27 @@ public class SciProject extends GenericOrganizationalUnit{ set(FUNDING, funding); } + public SciProjectSubProjectsCollection getSubProjects() { + return new SciProjectSubProjectsCollection( + (DataCollection) get(SUBPROJECTS)); + } + + public void addSubProject(SciProject project) { + Assert.exists((project), SciProject.class); + + DataObject link = add(SUBPROJECTS, project); + + link.set(SUBPROJECT_ORDER, + Integer.valueOf((int) getSubProjects().size())); + } + + public void removeSubProject(SciProject project) { + Assert.exists((project), SciProject.class); + + remove(SUBPROJECTS, project); + } + + public boolean hasSubProjects() { + return !this.getSearchSummary().isEmpty(); + } } diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectLoader.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectLoader.java index 0f23b2cf1..afb61f2e5 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectLoader.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectLoader.java @@ -1,8 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - package com.arsdigita.cms.contenttypes; /** diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectSubProjectsCollection.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectSubProjectsCollection.java new file mode 100644 index 000000000..2dc6ef6ed --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/SciProjectSubProjectsCollection.java @@ -0,0 +1,154 @@ +/* + * 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; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class SciProjectSubProjectsCollection extends DomainCollection { + + public String ORDER = "subProjectOrder"; + public String LINKORDER = "link.subProjectOrder"; + private static final Logger s_log = + Logger.getLogger( + SciProjectSubProjectsCollection.class); + + public SciProjectSubProjectsCollection(DataCollection dataCollection) { + super(dataCollection); + + m_dataCollection.addOrder(LINKORDER); + } + + public Integer getSubProjectOrder() { + return (Integer) m_dataCollection.get(LINKORDER); + } + + public void setSubProjectOrder(Integer order) { + DataObject link = (DataObject) this.get("link"); + + link.set(ORDER, order); + } + + public void swapWithNext(SciSubProject subproject) { + int currentPosition = 0; + int currentIndex = 0; + int nextIndex = 0; + + s_log.debug("Searching subproject..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getSubProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getSubProjectOrder(): %d", + getSubProjectOrder())); + if (this.getSubProject().equals(subproject)) { + break; + } + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided subproject is not " + + "part of this collection.")); + } + + if (this.next()) { + nextIndex = this.getSubProjectOrder(); + } else { + throw new IllegalArgumentException( + "The provided subproject is the last " + + "in the collection, so there is no next object " + + "to swap with."); + } + + this.rewind(); + + while (this.getPosition() != currentPosition) { + this.next(); + } + + this.setSubProjectOrder(nextIndex); + this.next(); + this.setSubProjectOrder(currentIndex); + this.rewind(); + } + + public void swapWithPrevious(SciSubProject subproject) { + int previousPosition = 0; + int previousIndex = 0; + int currentPosition = 0; + int currentIndex = 0; + + s_log.debug("Searching subproject..."); + this.rewind(); + while (this.next()) { + currentPosition = this.getPosition(); + currentIndex = this.getSubProjectOrder(); + s_log.debug(String.format("Position: %d(%d)/%d", currentPosition, + currentIndex, this.size())); + s_log.debug(String.format("getSubProjectOrder(): %d", + getSubProjectOrder())); + if (this.getSubProject().equals(subproject)) { + break; + } + + previousPosition = currentPosition; + previousIndex = currentIndex; + } + + if (currentPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided subproject is not " + + "part of this collection.")); + } + + if (previousPosition == 0) { + throw new IllegalArgumentException( + String.format( + "The provided subproject is the first one in this " + + "collection, so there is no previous one to switch " + + "with.")); + } + + this.rewind(); + while (this.getPosition() != previousPosition) { + this.next(); + } + + this.setSubProjectOrder(currentIndex); + this.next(); + this.setSubProjectOrder(previousIndex); + this.rewind(); + } + + public SciSubProject getSubProject() { + return new SciProject(m_dataCollection.getDataObject()); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectAddForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectAddForm.java new file mode 100644 index 000000000..983a360b6 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectAddForm.java @@ -0,0 +1,67 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciDepartment; +import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentProjectAddForm + extends BasicItemForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget m_itemSearch; + private final String ITEM_SEARCH = "projects"; + + public SciDepartmentProjectAddForm(ItemSelectionModel itemModel) { + super("ProjectsAddForm", itemModel); + } + + @Override + protected void addWidgets() { + add(new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.select_project").localize())); + m_itemSearch = new ItemSearchWidget( + ITEM_SEARCH, + ContentType.findByAssociatedObjectType( + SciProject.class.getName())); + add(m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + SciDepartment department = (SciDepartment) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton(). + isSelected(state))) { + department.addProject((SciProject) data.get(ITEM_SEARCH)); + } + + init(fse); + + + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsStep.java new file mode 100644 index 000000000..e6fcba282 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsStep.java @@ -0,0 +1,41 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentProjectsStep extends SimpleEditStep { + + private String ADD_PROJECT_SHEET_NAME = "addProject"; + + public SciDepartmentProjectsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public SciDepartmentProjectsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { + super(itemModel, parent, prefix); + + BasicItemForm addProjectSheet = + new SciDepartmentProjectAddForm(itemModel); + add(ADD_PROJECT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.add_project").localize(), + new WorkflowLockedComponentAccess(addProjectSheet, itemModel), + addProjectSheet.getSaveCancelSection().getCancelButton()); + + SciDepartmentProjectsTable projectsTable = + new SciDepartmentProjectsTable( + itemModel); + setDisplayComponent(projectsTable); + + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsTable.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsTable.java new file mode 100644 index 000000000..9adc03e0c --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentProjectsTable.java @@ -0,0 +1,315 @@ +package com.arsdigita.cms.contenttypes.ui; + +import java.math.BigDecimal; + +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.SciDepartment; +import com.arsdigita.cms.contenttypes.SciDepartmentProjectsCollection; +import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentProjectsTable + extends Table + implements TableActionListener { + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + private final String TABLE_COL_UP = "table_col_up"; + private final String TABLE_COL_DOWN = "table_col_down"; + private ItemSelectionModel m_itemModel; + + public SciDepartmentProjectsTable(ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView( + new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.projects.none"))); + + TableColumnModel colModel = getColumnModel(); + colModel.add(new TableColumn( + 0, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project").localize(), + TABLE_COL_EDIT)); + colModel.add(new TableColumn( + 1, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.remove").localize(), + TABLE_COL_DEL)); + colModel.add(new TableColumn( + 2, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.up").localize(), + TABLE_COL_UP)); + colModel.add(new TableColumn( + 3, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.down").localize(), + TABLE_COL_DOWN)); + + setModelBuilder( + new SciDepartmentProjectsTableModelBuilder(itemModel)); + + colModel.get(0).setCellRenderer(new EditCellRenderer()); + colModel.get(1).setCellRenderer(new DeleteCellRenderer()); + colModel.get(2).setCellRenderer(new UpCellRenderer()); + colModel.get(3).setCellRenderer(new DownCellRenderer()); + + addTableActionListener(this); + } + + private class SciDepartmentProjectsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public SciDepartmentProjectsTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + @Override + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + return new SciDepartmentProjectsTableModel(table, + state, + department); + } + } + + private class SciDepartmentProjectsTableModel + implements TableModel { + + private Table m_table; + private SciDepartmentProjectsCollection m_projects; + private SciProject m_project; + + public SciDepartmentProjectsTableModel(Table table, + PageState state, + SciDepartment department) { + m_table = table; + m_projects = department.getProjects(); + } + + @Override + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + boolean ret; + + if ((m_projects != null) && m_projects.next()) { + m_project = m_projects.getProject(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + @Override + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return m_project.getTitle(); + case 1: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.remove"). + localize(); + case 2: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.up"). + localize(); + case 3: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.down"). + localize(); + default: + return null; + } + } + + @Override + public Object getKeyAt(int columnIndex) { + return m_project.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 col) { + SecurityManager securityManager = + Utilities.getSecurityManager(state); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + department); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + 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); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.DELETE_ITEM, + department); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) SciOrganizationGlobalizationUtil. + globalize( + "sciorganization.ui.department.project." + + ".confirm_remove"). + localize()); + return link; + } else { + Label label = new Label(value.toString()); + return label; + } + } + } + + private class UpCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.up"). + localize()); + return link; + } + } + } + + private class DownCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.project.down"). + localize()); + return link; + } + } + } + + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + SciProject project = new SciProject( + new BigDecimal(event.getRowKey().toString())); + + SciDepartment department = + (SciDepartment) m_itemModel.getSelectedObject(state); + + SciDepartmentProjectsCollection projects = + department.getProjects(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + department.removeProject(project); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_UP)) { + projects.swapWithPrevious(project); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DOWN)) { + projects.swapWithNext(project); + } + } + + @Override + public void headSelected(TableActionEvent event) { + //Nothing to do. + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertiesStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertiesStep.java new file mode 100644 index 000000000..e55d5d139 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertiesStep.java @@ -0,0 +1,61 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Label; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentPropertiesStep + extends GenericOrganizationalUnitPropertiesStep { + + public SciDepartmentPropertiesStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + super(itemModel, parent); + } + + @Override + protected void addBasicProperties(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + SimpleEditStep basicProperties = new SimpleEditStep(itemModel, + parent, + EDIT_SHEET_NAME); + + BasicPageForm editBasicSheet = + new SciDepartmentPropertyForm(itemModel, this); + + basicProperties.add(EDIT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.edit_basic_properties"). + localize(), + new WorkflowLockedComponentAccess(editBasicSheet, + itemModel), + editBasicSheet.getSaveCancelSection(). + getCancelButton()); + + basicProperties.setDisplayComponent( + getGenericOrganizationalUnitPropertySheet(itemModel)); + + getSegmentedPanel().addSegment( + new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.basic_properties").localize()), + basicProperties); + } + + @Override + protected void addSteps(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + super.addSteps(itemModel, parent); + + addStep(new SciDepartmentSubDepartmentsStep(itemModel, parent), + "sciorganization.ui.department.subdepartments"); + + addStep(new SciDepartmentProjectsStep(itemModel, parent), + "sciorganization.ui.department.projects"); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertyForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertyForm.java new file mode 100644 index 000000000..1326e138d --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentPropertyForm.java @@ -0,0 +1,82 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciDepartment; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentPropertyForm + extends GenericOrganizationalUnitPropertyForm + implements FormProcessListener, + FormInitListener { + + public static final String ID = "SciDepartmentEdit"; + + public SciDepartmentPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + public SciDepartmentPropertyForm(ItemSelectionModel itemModel, + SciDepartmentPropertiesStep step) { + super(itemModel, step); + addSubmissionListener(this); + } + + @Override + public void addWidgets() { + super.addWidgets(); + + Label descLabel = new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganizations.ui.department.description")); + add(descLabel); + ParameterModel descParam = new StringParameter( + SciDepartment.DEPARTMENT_DESCRIPTION); + TextArea desc = new TextArea(descParam); + desc.setCols(60); + desc.setRows(18); + add(desc); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + super.init(fse); + + FormData data = fse.getFormData(); + SciDepartment department = (SciDepartment) super.initBasicWidgets(fse); + + data.put(SciDepartment.DEPARTMENT_DESCRIPTION, + department.getDepartmentDescription()); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + super.process(fse); + + FormData data = fse.getFormData(); + SciDepartment department = + (SciDepartment) super.processBasicWidgets(fse); + + if ((department != null) && getSaveCancelSection().getSaveButton(). + isSelected(fse.getPageState())) { + department.setDepartmentDescription( + (String) data.get(SciDepartment.DEPARTMENT_DESCRIPTION)); + + department.save(); + + init(fse); + } + + + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentAddForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentAddForm.java new file mode 100644 index 000000000..d396a2da6 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentAddForm.java @@ -0,0 +1,65 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciDepartment; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentSubDepartmentAddForm + extends BasicItemForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget m_itemSearch; + private final String ITEM_SEARCH = "subdepartments"; + + public SciDepartmentSubDepartmentAddForm(ItemSelectionModel itemModel) { + super("SubDepartmentsAddForm", itemModel); + } + + @Override + protected void addWidgets() { + add(new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.select_subdepartment"))); + m_itemSearch = new ItemSearchWidget( + ITEM_SEARCH, + ContentType.findByAssociatedObjectType(SciDepartment.class. + getName())); + add(m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + SciDepartment department = (SciDepartment) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton(). + isSelected(state))) { + department.addSubDepartment((SciDepartment) data.get(ITEM_SEARCH)); + } + + init(fse); + + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsStep.java new file mode 100644 index 000000000..0d97c2547 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsStep.java @@ -0,0 +1,40 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentSubDepartmentsStep extends SimpleEditStep { + + private String ADD_SUBDEPARTMENT_SHEET_NAME = "addSubDepartment"; + + public SciDepartmentSubDepartmentsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public SciDepartmentSubDepartmentsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { + super(itemModel, parent, prefix); + + BasicItemForm addSubDepartmentSheet = + new SciDepartmentSubDepartmentAddForm(itemModel); + add(ADD_SUBDEPARTMENT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.add_subdepartment").localize(), + new WorkflowLockedComponentAccess(addSubDepartmentSheet, itemModel), + addSubDepartmentSheet.getSaveCancelSection().getCancelButton()); + + SciDepartmentSubDepartmentsTable subdepartmentTable = + new SciDepartmentSubDepartmentsTable( + itemModel); + setDisplayComponent(subdepartmentTable); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsTable.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsTable.java new file mode 100644 index 000000000..f1d4f024f --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciDepartmentSubDepartmentsTable.java @@ -0,0 +1,313 @@ +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.SciDepartment; +import com.arsdigita.cms.contenttypes.SciDepartmentSubDepartmentsCollection; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class SciDepartmentSubDepartmentsTable + extends Table + implements TableActionListener { + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + private final String TABLE_COL_UP = "table_col_up"; + private final String TABLE_COL_DOWN = "table_col_down"; + private ItemSelectionModel m_itemModel; + + public SciDepartmentSubDepartmentsTable(ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView( + new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartments.none"))); + + TableColumnModel colModel = getColumnModel(); + colModel.add(new TableColumn( + 0, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment").localize(), + TABLE_COL_EDIT)); + colModel.add(new TableColumn( + 1, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.remove").localize(), + TABLE_COL_DEL)); + colModel.add(new TableColumn( + 2, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.up").localize(), + TABLE_COL_UP)); + colModel.add(new TableColumn( + 3, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.down").localize(), + TABLE_COL_DOWN)); + + setModelBuilder( + new SciDepartmentSubDepartmentsTableModelBuilder(itemModel)); + + colModel.get(0).setCellRenderer(new EditCellRenderer()); + colModel.get(1).setCellRenderer(new DeleteCellRenderer()); + colModel.get(2).setCellRenderer(new UpCellRenderer()); + colModel.get(3).setCellRenderer(new DownCellRenderer()); + + addTableActionListener(this); + } + + private class SciDepartmentSubDepartmentsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public SciDepartmentSubDepartmentsTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + @Override + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + return new SciDepartmentSubDepartmentsTableModel(table, + state, + department); + } + } + + private class SciDepartmentSubDepartmentsTableModel + implements TableModel { + + private Table m_table; + private SciDepartmentSubDepartmentsCollection m_subdepartments; + private SciDepartment m_subdepartment; + + private SciDepartmentSubDepartmentsTableModel(Table table, + PageState state, + SciDepartment department) { + m_table = table; + m_subdepartments = department.getSubDepartments(); + } + + @Override + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + boolean ret; + + if ((m_subdepartments != null) && m_subdepartments.next()) { + m_subdepartment = m_subdepartments.getSubDepartment(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + @Override + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return m_subdepartment.getTitle(); + case 1: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.remove"). + localize(); + case 2: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.up"). + localize(); + case 3: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.down"). + localize(); + default: + return null; + } + } + + @Override + public Object getKeyAt(int columnIndex) { + return m_subdepartment.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 col) { + SecurityManager securityManager = + Utilities.getSecurityManager(state); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + department); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + 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); + SciDepartment department = (SciDepartment) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.DELETE_ITEM, + department); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) SciOrganizationGlobalizationUtil. + globalize( + "sciorganization.ui.department.subdepartment." + + ".confirm_remove"). + localize()); + return link; + } else { + Label label = new Label(value.toString()); + return label; + } + } + } + + private class UpCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.up"). + localize()); + return link; + } + } + } + + private class DownCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.department.subdepartment.down"). + localize()); + return link; + } + } + } + + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + SciDepartment subdepartment = new SciDepartment( + new BigDecimal(event.getRowKey().toString())); + + SciDepartment department = + (SciDepartment) m_itemModel.getSelectedObject(state); + + SciDepartmentSubDepartmentsCollection subdepartments = + department.getSubDepartments(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + department.removeSubDepartment(department); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_UP)) { + subdepartments.swapWithPrevious(department); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DOWN)) { + subdepartments.swapWithNext(department); + } + } + + @Override + public void headSelected(TableActionEvent event) { + //Nothing to do. + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentAddForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentAddForm.java new file mode 100644 index 000000000..5f0e5775b --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentAddForm.java @@ -0,0 +1,65 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciDepartment; +import com.arsdigita.cms.contenttypes.SciOrganization; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationDepartmentAddForm + extends BasicItemForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget m_itemSearch; + private final String ITEM_SEARCH = "departments"; + + public SciOrganizationDepartmentAddForm(ItemSelectionModel itemModel) { + super("DepartmentsAddForm", itemModel); + } + + @Override + protected void addWidgets() { + add(new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.select_department").localize())); + m_itemSearch = new ItemSearchWidget( + ITEM_SEARCH, + ContentType.findByAssociatedObjectType( + SciDepartment.class.getName())); + add(m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + SciOrganization orga = (SciOrganization) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton(). + isSelected(state))) { + orga.addDepartment((SciDepartment) data.get(ITEM_SEARCH)); + } + + init(fse); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsStep.java new file mode 100644 index 000000000..9aba27c99 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsStep.java @@ -0,0 +1,40 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationDepartmentsStep extends SimpleEditStep { + + private String ADD_DEPARTMENT_SHEET_NAME = "addDepartment"; + + public SciOrganizationDepartmentsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public SciOrganizationDepartmentsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { + super(itemModel, parent, prefix); + + BasicItemForm addDepartmentSheet = + new SciOrganizationDepartmentAddForm(itemModel); + add(ADD_DEPARTMENT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.add_department").localize(), + new WorkflowLockedComponentAccess(addDepartmentSheet, itemModel), + addDepartmentSheet.getSaveCancelSection().getCancelButton()); + + SciOrganizationDepartmentsTable departmentTable = + new SciOrganizationDepartmentsTable( + itemModel); + setDisplayComponent(departmentTable); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsTable.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsTable.java new file mode 100644 index 000000000..cc9aab56b --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationDepartmentsTable.java @@ -0,0 +1,314 @@ +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.SciDepartment; +import com.arsdigita.cms.contenttypes.SciOrganization; +import com.arsdigita.cms.contenttypes.SciOrganizationDepartmentsCollection; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationDepartmentsTable + extends Table + implements TableActionListener { + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + private final String TABLE_COL_UP = "table_col_up"; + private final String TABLE_COL_DOWN = "table_col_down"; + private ItemSelectionModel m_itemModel; + + public SciOrganizationDepartmentsTable(ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView( + new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.departments.none"))); + + TableColumnModel colModel = getColumnModel(); + colModel.add(new TableColumn( + 0, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department").localize(), + TABLE_COL_EDIT)); + colModel.add(new TableColumn( + 1, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.remove").localize(), + TABLE_COL_DEL)); + colModel.add(new TableColumn( + 2, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.up").localize(), + TABLE_COL_UP)); + colModel.add(new TableColumn( + 3, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.down").localize(), + TABLE_COL_DOWN)); + + setModelBuilder( + new SciOrganizationDepartmentsTableModelBuilder(itemModel)); + + colModel.get(0).setCellRenderer(new EditCellRenderer()); + colModel.get(1).setCellRenderer(new DeleteCellRenderer()); + colModel.get(2).setCellRenderer(new UpCellRenderer()); + colModel.get(3).setCellRenderer(new DownCellRenderer()); + + addTableActionListener(this); + } + + private class SciOrganizationDepartmentsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public SciOrganizationDepartmentsTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + @Override + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + return new SciOrganizationDepartmentsTableModel(table, + state, + orga); + } + } + + private class SciOrganizationDepartmentsTableModel + implements TableModel { + + private Table m_table; + private SciOrganizationDepartmentsCollection m_departments; + private SciDepartment m_department; + + private SciOrganizationDepartmentsTableModel(Table table, + PageState state, + SciOrganization orga) { + m_table = table; + m_departments = orga.getDepartments(); + } + + @Override + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + boolean ret; + + if ((m_departments != null) && m_departments.next()) { + m_department = m_departments.getDepartment(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + @Override + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return m_department.getTitle(); + case 1: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.remove"). + localize(); + case 2: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.up"). + localize(); + case 3: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.down"). + localize(); + default: + return null; + } + } + + @Override + public Object getKeyAt(int columnIndex) { + return m_department.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 col) { + SecurityManager securityManager = + Utilities.getSecurityManager(state); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + orga); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + 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); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.DELETE_ITEM, + orga); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) SciOrganizationGlobalizationUtil. + globalize( + "sciorganization.ui.organization.department." + + ".confirm_remove"). + localize()); + return link; + } else { + Label label = new Label(value.toString()); + return label; + } + } + } + + private class UpCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.up"). + localize()); + return link; + } + } + } + + private class DownCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.department.down"). + localize()); + return link; + } + } + } + + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + SciDepartment department = new SciDepartment( + new BigDecimal(event.getRowKey().toString())); + + SciOrganization orga = + (SciOrganization) m_itemModel.getSelectedObject(state); + + SciOrganizationDepartmentsCollection departments = + orga.getDepartments(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + orga.removeDepartment(department); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_UP)) { + departments.swapWithPrevious(department); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DOWN)) { + departments.swapWithNext(department); + } + } + + @Override + public void headSelected(TableActionEvent event) { + //Nothing to do. + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationGlobalizationUtil.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationGlobalizationUtil.java new file mode 100644 index 000000000..7718bffce --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationGlobalizationUtil.java @@ -0,0 +1,21 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.globalization.GlobalizedMessage; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationGlobalizationUtil { + + public static final String BUNDLE_NAME = "com.arsdigita.cms.contenttypes.ui.OrganizationResources"; + + public static GlobalizedMessage globalize(String key) { + return new GlobalizedMessage(key, BUNDLE_NAME); + } + + public static GlobalizedMessage globalize(String key, Object[] args) { + return new GlobalizedMessage(key, BUNDLE_NAME, args); + } + +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectAddForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectAddForm.java new file mode 100644 index 000000000..85c1ad316 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectAddForm.java @@ -0,0 +1,65 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciOrganization; +import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationProjectAddForm + extends BasicItemForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget m_itemSearch; + private final String ITEM_SEARCH = "projects"; + + public SciOrganizationProjectAddForm(ItemSelectionModel itemModel) { + super("ProjectsAddForm", itemModel); + } + + @Override + protected void addWidgets() { + add(new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.select_project").localize())); + m_itemSearch = new ItemSearchWidget( + ITEM_SEARCH, + ContentType.findByAssociatedObjectType( + SciProject.class.getName())); + add(m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + SciOrganization orga = (SciOrganization) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton(). + isSelected(state))) { + orga.addProject((SciProject) data.get(ITEM_SEARCH)); + } + + init(fse); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsStep.java new file mode 100644 index 000000000..527d54fde --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsStep.java @@ -0,0 +1,40 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationProjectsStep extends SimpleEditStep { + + private String ADD_PROJECT_SHEET_NAME = "addProject"; + + public SciOrganizationProjectsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public SciOrganizationProjectsStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { + super(itemModel, parent, prefix); + + BasicItemForm addProjectSheet = + new SciOrganizationProjectAddForm(itemModel); + add(ADD_PROJECT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.add_project").localize(), + new WorkflowLockedComponentAccess(addProjectSheet, itemModel), + addProjectSheet.getSaveCancelSection().getCancelButton()); + + SciOrganizationProjectsTable projectsTable = + new SciOrganizationProjectsTable( + itemModel); + setDisplayComponent(projectsTable); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsTable.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsTable.java new file mode 100644 index 000000000..217e3de4f --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationProjectsTable.java @@ -0,0 +1,315 @@ +package com.arsdigita.cms.contenttypes.ui; + +import java.math.BigDecimal; + +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.SciOrganization; +import com.arsdigita.cms.contenttypes.SciOrganizationProjectsCollection; +import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationProjectsTable + extends Table + implements TableActionListener { + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + private final String TABLE_COL_UP = "table_col_up"; + private final String TABLE_COL_DOWN = "table_col_down"; + private ItemSelectionModel m_itemModel; + + public SciOrganizationProjectsTable(ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView( + new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.projects.none"))); + + TableColumnModel colModel = getColumnModel(); + colModel.add(new TableColumn( + 0, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project").localize(), + TABLE_COL_EDIT)); + colModel.add(new TableColumn( + 1, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.remove").localize(), + TABLE_COL_DEL)); + colModel.add(new TableColumn( + 2, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.up").localize(), + TABLE_COL_UP)); + colModel.add(new TableColumn( + 3, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.down").localize(), + TABLE_COL_DOWN)); + + setModelBuilder( + new SciOrganizationProjectsTableModelBuilder(itemModel)); + + colModel.get(0).setCellRenderer(new EditCellRenderer()); + colModel.get(1).setCellRenderer(new DeleteCellRenderer()); + colModel.get(2).setCellRenderer(new UpCellRenderer()); + colModel.get(3).setCellRenderer(new DownCellRenderer()); + + addTableActionListener(this); + } + + private class SciOrganizationProjectsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public SciOrganizationProjectsTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + @Override + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + return new SciOrganizationProjectsTableModel(table, + state, + orga); + } + } + + private class SciOrganizationProjectsTableModel + implements TableModel { + + private Table m_table; + private SciOrganizationProjectsCollection m_projects; + private SciProject m_project; + + public SciOrganizationProjectsTableModel(Table table, + PageState state, + SciOrganization orga) { + m_table = table; + m_projects = orga.getProjects(); + } + + @Override + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + boolean ret; + + if ((m_projects != null) && m_projects.next()) { + m_project = m_projects.getProject(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + @Override + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return m_project.getTitle(); + case 1: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.remove"). + localize(); + case 2: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.up"). + localize(); + case 3: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.down"). + localize(); + default: + return null; + } + } + + @Override + public Object getKeyAt(int columnIndex) { + return m_project.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 col) { + SecurityManager securityManager = + Utilities.getSecurityManager(state); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + orga); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + 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); + SciOrganization orga = (SciOrganization) m_itemModel. + getSelectedObject(state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.DELETE_ITEM, + orga); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) SciOrganizationGlobalizationUtil. + globalize( + "sciorganization.ui.organization.project." + + ".confirm_remove"). + localize()); + return link; + } else { + Label label = new Label(value.toString()); + return label; + } + } + } + + private class UpCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.up"). + localize()); + return link; + } + } + } + + private class DownCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.project.down"). + localize()); + return link; + } + } + } + + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + SciProject project = new SciProject( + new BigDecimal(event.getRowKey().toString())); + + SciOrganization orga = + (SciOrganization) m_itemModel.getSelectedObject(state); + + SciOrganizationProjectsCollection projects = + orga.getProjects(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + orga.removeProject(project); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_UP)) { + projects.swapWithPrevious(project); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DOWN)) { + projects.swapWithNext(project); + } + } + + @Override + public void headSelected(TableActionEvent event) { + //Nothing to do. + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertiesStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertiesStep.java new file mode 100644 index 000000000..0a90836a1 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertiesStep.java @@ -0,0 +1,61 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.Label; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationPropertiesStep + extends GenericOrganizationalUnitPropertiesStep { + + public SciOrganizationPropertiesStep(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + super(itemModel, parent); + } + + @Override + protected void addBasicProperties(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + SimpleEditStep basicProperties = new SimpleEditStep(itemModel, + parent, + EDIT_SHEET_NAME); + + BasicPageForm editBasicSheet = + new SciOrganizationPropertyForm(itemModel, this); + + basicProperties.add(EDIT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.edit_basic_sheet").localize(), + new WorkflowLockedComponentAccess(editBasicSheet, + itemModel), + editBasicSheet.getSaveCancelSection(). + getCancelButton()); + + basicProperties.setDisplayComponent( + getGenericOrganizationalUnitPropertySheet(itemModel)); + + getSegmentedPanel().addSegment( + new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.organization.basic_properties"). + localize()), + basicProperties); + } + + @Override + protected void addSteps(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + super.addSteps(itemModel, parent); + + addStep(new SciOrganizationDepartmentsStep(itemModel, parent), + "sciorganization.ui.organization.departments"); + + addStep(new SciOrganizationProjectsStep(itemModel, parent), + "sciorganization.ui.organization.projects"); + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertyForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertyForm.java new file mode 100644 index 000000000..16229cc13 --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciOrganizationPropertyForm.java @@ -0,0 +1,79 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciOrganization; + +/** + * + * @author Jens Pelzetter + */ +public class SciOrganizationPropertyForm + extends GenericOrganizationalUnitPropertyForm + implements FormProcessListener, + FormInitListener { + + public static final String ID = "SciOrganizationEdit"; + + public SciOrganizationPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + public SciOrganizationPropertyForm(ItemSelectionModel itemModel, + SciOrganizationPropertiesStep step) { + super(itemModel, step); + addSubmissionListener(this); + } + + @Override + protected void addWidgets() { + super.addWidgets(); + + Label descLabel = new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganizations.ui.organization.description")); + add(descLabel); + ParameterModel descParam = new StringParameter( + SciOrganization.ORGANIZATION_DESCRIPTION); + TextArea desc = new TextArea(descParam); + desc.setCols(60); + desc.setRows(18); + add(desc); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + super.init(fse); + + FormData data = fse.getFormData(); + SciOrganization orga = (SciOrganization) super.initBasicWidgets(fse); + + data.put(SciOrganization.ORGANIZATION_DESCRIPTION, + orga.getOrganizationDescription()); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + super.process(fse); + + FormData data = fse.getFormData(); + SciOrganization organization = (SciOrganization) super.processBasicWidgets(fse); + + if ((organization != null) && getSaveCancelSection().getSaveButton(). + isSelected(fse.getPageState())) { + organization.setDescription((String) data.get( + SciOrganization.ORGANIZATION_DESCRIPTION)); + + organization.save(); + + init(fse); + } + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertiesStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertiesStep.java index 74e3c4ae1..904cc7259 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertiesStep.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertiesStep.java @@ -4,8 +4,12 @@ */ package com.arsdigita.cms.contenttypes.ui; +import com.arsdigita.bebop.Label; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; /** * @@ -15,21 +19,53 @@ public class SciProjectPropertiesStep extends GenericOrganizationalUnitPropertiesStep { public SciProjectPropertiesStep(ItemSelectionModel itemModel, - AuthoringKitWizard parent) { + AuthoringKitWizard parent) { super(itemModel, parent); } + @Override + protected void addBasicProperties(ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + SimpleEditStep basicProperties = new SimpleEditStep(itemModel, + parent, + EDIT_SHEET_NAME); + + BasicPageForm editBasicSheet = + new SciProjectPropertyForm(itemModel, this); + + basicProperties.add(EDIT_SHEET_NAME, + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.edit_basic_sheet").localize(), + new WorkflowLockedComponentAccess(editBasicSheet, + itemModel), + editBasicSheet.getSaveCancelSection(). + getCancelButton()); + + basicProperties.setDisplayComponent( + getGenericOrganizationalUnitPropertySheet(itemModel)); + + getSegmentedPanel().addSegment( + new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.basic_properties"). + localize()), + basicProperties); + } + @Override protected void addSteps(ItemSelectionModel itemModel, AuthoringKitWizard parent) { - addStep(new GenericOrganizationalUnitContactPropertiesStep(itemModel, - parent), - "cms.contenttypes.ui.orgaunit.contact"); - addStep(new SciProjectSubprojectPropertiesStep(itemModel, - parent), - "cms.contenttypes.ui.project.subprojects"); + /*addStep(new GenericOrganizationalUnitContactPropertiesStep(itemModel, + parent), + "cms.contenttypes.ui.orgaunit.contact"); addStep(new GenericOrganizationalUnitPersonPropertiesStep(itemModel, - parent), - "cms.contenttypes.ui.orgaunit.persons"); + parent), + "cms.contenttypes.ui.orgaunit.persons");*/ + + super.addSteps(itemModel, parent); + + addStep(new SciProjectSubprojectsStep(itemModel, + parent), + "cms.contenttypes.ui.project.subprojects"); + } } diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertyForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertyForm.java new file mode 100644 index 000000000..0cc0866dd --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectPropertyForm.java @@ -0,0 +1,78 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.SciProject; + +/** + * + * @author Jens Pelzetter + */ +public class SciProjectPropertyForm + extends GenericOrganizationalUnitPropertyForm + implements FormProcessListener, + FormInitListener, + FormSubmissionListener { + + public static final String ID = "SciProjectEdit"; + + public SciProjectPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + public SciProjectPropertyForm(ItemSelectionModel itemModel, + SciProjectPropertiesStep step) { + super(itemModel, step); + addSubmissionListener(this); + } + + @Override + protected void addWidgets() { + super.addWidgets(); + + Label descLabel = new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganizations.ui.project.description")); + add(descLabel); + ParameterModel descParam = new StringParameter(SciProject.PROJECT_DESCRIPTION); + TextArea desc = new TextArea(descParam); + desc.setCols(60); + desc.setRows(18); + add(desc); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + super.init(fse); + + FormData data = fse.getFormData(); + SciProject project = (SciProject) super.initBasicWidgets(fse); + + data.put(SciProject.PROJECT_DESCRIPTION, project.getDescription()); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + super.process(fse); + + FormData data = fse.getFormData(); + SciProject project = (SciProject) super.processBasicWidgets(fse); + + if ((project != null) && getSaveCancelSection().getSaveButton(). + isSelected(fse.getPageState())) { + project.setDescription((String) data.get(SciProject.PROJECT_DESCRIPTION)); + + project.save(); + + init(fse); + } + } +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubProjectsTable.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubProjectsTable.java new file mode 100644 index 000000000..4f749f73f --- /dev/null +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubProjectsTable.java @@ -0,0 +1,314 @@ +package com.arsdigita.cms.contenttypes.ui; + +import java.math.BigDecimal; + +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.SciProject; +import com.arsdigita.cms.contenttypes.SciProjectSubProjectsCollection; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; + +/** + * + * @author Jens Pelzetter + */ +public class SciProjectSubProjectsTable + extends Table + implements TableActionListener { + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + private final String TABLE_COL_UP = "table_col_up"; + private final String TABLE_COL_DOWN = "table_col_down"; + private ItemSelectionModel m_itemModel; + + public SciProjectSubProjectsTable(ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView( + new Label(SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subprojects.none"))); + + TableColumnModel colModel = getColumnModel(); + colModel.add(new TableColumn( + 0, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject").localize(), + TABLE_COL_EDIT)); + colModel.add(new TableColumn( + 1, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.remove").localize(), + TABLE_COL_DEL)); + colModel.add(new TableColumn( + 2, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.up").localize(), + TABLE_COL_UP)); + colModel.add(new TableColumn( + 3, + SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.down").localize(), + TABLE_COL_DOWN)); + + setModelBuilder( + new SciProjectSubProjectsTableModelBuilder(itemModel)); + + colModel.get(0).setCellRenderer(new EditCellRenderer()); + colModel.get(1).setCellRenderer(new DeleteCellRenderer()); + colModel.get(2).setCellRenderer(new UpCellRenderer()); + colModel.get(3).setCellRenderer(new DownCellRenderer()); + + addTableActionListener(this); + } + + private class SciProjectSubProjectsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public SciProjectSubProjectsTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + @Override + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + SciProject project = (SciProject) m_itemModel.getSelectedObject( + state); + return new SciProjectSubProjectsTableModel(table, + state, + project); + } + } + + private class SciProjectSubProjectsTableModel + implements TableModel { + + private Table m_table; + private SciProjectSubProjectsCollection m_subprojects; + private SciProject m_subproject; + + public SciProjectSubProjectsTableModel(Table table, + PageState state, + SciProject project) { + m_table = table; + m_subprojects = project.getSubProjects(); + } + + @Override + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + @Override + public boolean nextRow() { + boolean ret; + + if ((m_subprojects != null) && m_subprojects.next()) { + m_subproject = m_subprojects.getSubProject(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + @Override + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return m_subproject.getTitle(); + case 1: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.remove"). + localize(); + case 2: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.up"). + localize(); + case 3: + return SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.down"). + localize(); + default: + return null; + } + } + + @Override + public Object getKeyAt(int columnIndex) { + return m_subproject.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 col) { + SecurityManager securityManager = + Utilities.getSecurityManager(state); + SciProject project = (SciProject) m_itemModel.getSelectedObject( + state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + project); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + 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); + SciProject project = (SciProject) m_itemModel.getSelectedObject( + state); + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.DELETE_ITEM, + project); + + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) SciOrganizationGlobalizationUtil. + globalize( + "sciorganization.ui.project.subproject." + + ".confirm_remove"). + localize()); + return link; + } else { + Label label = new Label(value.toString()); + return label; + } + } + } + + private class UpCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.up"). + localize()); + return link; + } + } + } + + private class DownCellRenderer + extends LockableImpl + implements TableCellRenderer { + + @Override + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + + if (0 == row) { + Label label = new Label(""); + return label; + } else { + ControlLink link = new ControlLink( + (String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.subproject.down"). + localize()); + return link; + } + } + } + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + SciProject subProject = new SciProject( + new BigDecimal(event.getRowKey().toString())); + + SciProject project = + (SciProject) m_itemModel.getSelectedObject(state); + + SciProjectSubProjectsCollection subprojects = + project.getSubProjects(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (column.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + project.removeSubProject(subProject); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_UP)) { + subprojects.swapWithPrevious(subProject); + } else if (column.getHeaderKey().toString().equals(TABLE_COL_DOWN)) { + subprojects.swapWithNext(subProject); + } + } + + @Override + public void headSelected(TableActionEvent event) { + //Nothing to do. + } + +} diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectAddForm.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectAddForm.java index 0838a4752..b0bc82469 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectAddForm.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectAddForm.java @@ -1,21 +1,64 @@ package com.arsdigita.cms.contenttypes.ui; +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.contenttypes.SciProject; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; /** * * @author Jens Pelzetter */ public class SciProjectSubprojectAddForm - extends GenericOrganizationalUnitChildAddForm { + extends BasicItemForm + implements FormProcessListener, + FormInitListener { + + private ItemSearchWidget m_itemSearch; + private final String ITEM_SEARCH = "projects"; public SciProjectSubprojectAddForm(ItemSelectionModel itemModel) { super("SubprojectAddForm", itemModel); } @Override - protected String getChildDataObjectType() { - return SciProject.BASE_DATA_OBJECT_TYPE; + protected void addWidgets() { + add(new Label((String) SciOrganizationGlobalizationUtil.globalize( + "sciorganization.ui.project.select_subproject").localize())); + m_itemSearch = new ItemSearchWidget( + ITEM_SEARCH, + ContentType.findByAssociatedObjectType( + SciProject.class.getName())); + add(m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) throws FormProcessException { + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + SciProject project = (SciProject) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton(). + isSelected(state))) { + project.addSubProject((SciProject) data.get(ITEM_SEARCH)); + } + + init(fse); } } diff --git a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectPropertiesStep.java b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectsStep.java similarity index 59% rename from ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectPropertiesStep.java rename to ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectsStep.java index 628b96b72..b7700ee4b 100644 --- a/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectPropertiesStep.java +++ b/ccm-sci-types-organization/src/com/arsdigita/cms/contenttypes/ui/SciProjectSubprojectsStep.java @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.cms.ItemSelectionModel; @@ -16,32 +12,33 @@ import org.apache.log4j.Logger; * * @author Jens Pelzetter */ -public class SciProjectSubprojectPropertiesStep extends SimpleEditStep { +public class SciProjectSubprojectsStep extends SimpleEditStep { private final static Logger s_log = Logger.getLogger( - SciProjectSubprojectPropertiesStep.class); + SciProjectSubprojectsStep.class); private String ADD_CHILD_SHEET_NAME = "addChild"; - public SciProjectSubprojectPropertiesStep(ItemSelectionModel itemModel, + public SciProjectSubprojectsStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { this(itemModel, parent, null); } - public SciProjectSubprojectPropertiesStep( + public SciProjectSubprojectsStep( ItemSelectionModel itemModel, AuthoringKitWizard parent, String prefix) { super(itemModel, parent, prefix); - BasicItemForm addChildSheet = new SciProjectSubprojectAddForm(itemModel); + BasicItemForm addSubProjectSheet = + new SciProjectSubprojectAddForm(itemModel); add(ADD_CHILD_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize( "cms.contenttypes.ui.genericorgaunit.add_child").localize(), - new WorkflowLockedComponentAccess(addChildSheet, itemModel), - addChildSheet.getSaveCancelSection().getCancelButton()); + new WorkflowLockedComponentAccess(addSubProjectSheet, itemModel), + addSubProjectSheet.getSaveCancelSection().getCancelButton()); - GenericOrganizationalUnitChildTable childrenTable = new GenericOrganizationalUnitChildTable( + SciProjectSubProjectsTable subProjectsTable = new SciProjectSubProjectsTable( itemModel); - setDisplayComponent(childrenTable); + setDisplayComponent(subProjectsTable); } }