From e56909c9cc162d24ee4dbc1bcc8605b486fc9de8 Mon Sep 17 00:00:00 2001 From: jensp Date: Fri, 15 Jun 2012 13:53:07 +0000 Subject: [PATCH] =?UTF-8?q?-=20CategoryAdminPane=20zeigt=20den=20Link=20zu?= =?UTF-8?q?m=20L=C3=B6schen=20von=20Kategorien=20nicht=20mehr=20f=C3=BCr?= =?UTF-8?q?=20Kategorien=20an,=20die=20gleichzeitig=20Terms=20sind.=20-=20?= =?UTF-8?q?Formatierungen=20und=20Doku?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1711 8810af33-2d31-482b-a856-94f89814c4df --- .../arsdigita/cms/dabin/PersonImporter.java | 123 +++++++------ ...ublicPersonalProfileOwnerAssocUpgrade.java | 2 +- .../com/arsdigita/cms/CMSResources.properties | 1 + .../arsdigita/cms/CMSResources_de.properties | 1 + .../cms/CMSResources_en_GB.properties | 1 + .../arsdigita/cms/CMSResources_fr.properties | 1 + .../cms/ui/ItemSearchFlatBrowsePane.java | 30 +++- .../arsdigita/cms/ui/ItemSearchSection.java | 2 +- .../cms/ui/category/CategoryAdminPane.java | 168 ++++++++++-------- 9 files changed, 193 insertions(+), 136 deletions(-) diff --git a/ccm-cms-dabinpersonimporter/src/com/arsdigita/cms/dabin/PersonImporter.java b/ccm-cms-dabinpersonimporter/src/com/arsdigita/cms/dabin/PersonImporter.java index fa1194c77..32dbf540f 100644 --- a/ccm-cms-dabinpersonimporter/src/com/arsdigita/cms/dabin/PersonImporter.java +++ b/ccm-cms-dabinpersonimporter/src/com/arsdigita/cms/dabin/PersonImporter.java @@ -8,17 +8,19 @@ import com.arsdigita.cms.Folder; import com.arsdigita.cms.contentassets.RelatedLink; import com.arsdigita.cms.contenttypes.Address; import com.arsdigita.cms.contenttypes.Contact; +import com.arsdigita.cms.contenttypes.GenericContactBundle; import com.arsdigita.cms.contenttypes.GenericContactEntry; import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.GenericPersonBundle; import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.contenttypes.SciMember; import com.arsdigita.cms.lifecycle.Lifecycle; import com.arsdigita.cms.lifecycle.LifecycleDefinition; import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection; import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.packaging.Program; import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.TransactionContext; +import com.arsdigita.util.cmd.Program; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -68,7 +70,7 @@ public class PersonImporter extends Program { private Folder addressFolder; private Category membersActiveCategory; private Category membersFormerCategory; - private Category membersAssociatedCategory; + //private Category membersAssociatedCategory; //Department key -> category private final Map membersActiveDepartmentCategories = new TreeMap(); @@ -149,8 +151,7 @@ public class PersonImporter extends Program { addressSection = getContentSection((config.getProperty( "address.contentsection"))); - LifecycleDefinitionCollection lifecycles = membersSection. - getLifecycleDefinitions(); + LifecycleDefinitionCollection lifecycles = membersSection.getLifecycleDefinitions(); while (lifecycles.next()) { membersLifecycle = lifecycles.getLifecycleDefinition(); } @@ -203,9 +204,9 @@ public class PersonImporter extends Program { "members.active.category"))); membersFormerCategory = new Category(new BigDecimal(config.getProperty( "members.former.category"))); - membersAssociatedCategory = new Category(new BigDecimal(config. - getProperty( - "members.associated.category"))); +// membersAssociatedCategory = new Category(new BigDecimal(config. +// getProperty( +// "members.associated.category"))); //Get department ids from DaBIn DB //Create connection to the DaBIn MySQL database @@ -304,16 +305,13 @@ public class PersonImporter extends Program { System.out.println("Configuration values:"); System.out.println("---------------------"); - System.out.printf("membersSection = %s\n", membersSection. - getName()); + System.out.printf("membersSection = %s\n", membersSection.getName()); System.out.printf("membersContactsSection = %s\n", membersContactsSection.getName()); - System.out.printf("authorsSection = %s\n", authorsSection. - getName()); + System.out.printf("authorsSection = %s\n", authorsSection.getName()); System.out.printf("authorsContactsSection = %s\n", authorsContactsSection.getName()); - System.out.printf("personsSection = %s\n", personsSection. - getName()); + System.out.printf("personsSection = %s\n", personsSection.getName()); System.out.printf("personsContactsSection = %s\n", personsContactsSection.getName()); System.out.println(""); @@ -336,8 +334,8 @@ public class PersonImporter extends Program { membersActiveCategory.getName()); System.out.printf("membersFormerCategory = %s\n", membersFormerCategory.getName()); - System.out.printf("membersAssociatedCategory = %s\n", - membersAssociatedCategory.getName()); +// System.out.printf("membersAssociatedCategory = %s\n", +// membersAssociatedCategory.getName()); System.out.println( "Categories for active members in the departments " @@ -422,16 +420,18 @@ public class PersonImporter extends Program { address.setCity(config.getProperty("address.city")); address.setIsoCountryCode(config.getProperty("address.country")); address.setLanguage("de"); + address.save(); final ContentBundle addressBundle = new ContentBundle(address); addressBundle.setDefaultLanguage("de"); address.setContentSection(addressSection); addressBundle.setContentSection(addressSection); - addressFolder.addItem(addressBundle); + addressBundle.save(); + addressFolder.addItem(addressBundle); try { - while (result.next()) { + while (result.next()) { System.out.printf("Processing person '%d' of '%d':\n", i, number); System.out.printf("\tPerson_Id = %s\n", @@ -461,6 +461,7 @@ public class PersonImporter extends Program { LifecycleDefinition lifecycleDefinition = null; LifecycleDefinition contactLifecycleDefinition = null; Category category = null; + System.out.println("Eigenschaft..."); if ("Aktiv".equals(result.getString("person.Eigenschaft"))) { person = new SciMember(); section = membersSection; @@ -482,23 +483,25 @@ public class PersonImporter extends Program { lifecycleDefinition = membersLifecycle; contactLifecycleDefinition = membersContactsLifecycle; category = membersFormerCategory; - } else if ("Assoziert".equals(result.getString( - "person.Eigenschaft"))) { - person = new SciMember(); - section = membersSection; - folder = membersFolder; - contactsSection = membersContactsSection; - contactsFolder = membersContactsFolder; - category = membersAssociatedCategory; - lifecycleDefinition = membersLifecycle; - category = membersAssociatedCategory; - contactLifecycleDefinition = membersContactsLifecycle; - } + } +// } else if ("Assoziert".equals(result.getString( +// "person.Eigenschaft"))) { +// person = new SciMember(); +// section = membersSection; +// folder = membersFolder; +// contactsSection = membersContactsSection; +// contactsFolder = membersContactsFolder; +// category = membersAssociatedCategory; +// lifecycleDefinition = membersLifecycle; +// category = membersAssociatedCategory; +// contactLifecycleDefinition = membersContactsLifecycle; +// } + System.out.println("Person basic data..."); person.setSurname(result.getString("person.Name")); person.setGivenName(result.getString("person.Vorname")); person.setTitlePre(result.getString("person.Anrede")); - person.setDabinId(result.getInt("person.Person_Id")); + //person.setDabinId(result.getInt("person.Person_Id")); person.setLanguage("de"); person.setContentSection(section); person.setLifecycle(createLifecycle(lifecycleDefinition)); @@ -506,7 +509,7 @@ public class PersonImporter extends Program { resolveDuplicateNameAndTitle(person, folder); - ContentBundle personBundle = new ContentBundle(person); + GenericPersonBundle personBundle = new GenericPersonBundle(person); personBundle.setDefaultLanguage("de"); personBundle.setContentSection(section); folder.addItem(personBundle); @@ -519,6 +522,7 @@ public class PersonImporter extends Program { category.addChild(personBundle); } + System.out.println("Department assoc..."); if ("Aktiv".equals(result.getString("person.Eigenschaft")) || "Ehemalig".equals(result.getString( "person.Eigenschaft")) @@ -531,17 +535,14 @@ public class PersonImporter extends Program { if ("Aktiv".equals(result.getString( "person.Eigenschaft"))) { depCat = - membersActiveDepartmentCategories.get(result. - getString("abteilunglink.Abteilung_Id")); + membersActiveDepartmentCategories.get(result.getString("abteilunglink.Abteilung_Id")); } else if ("Ehemalig".equals(result.getString( "person.Eigenschaft"))) { depCat = - membersFormerDepartmentCategories.get(result. - getString("abteilunglink.Abteilung_Id")); + membersFormerDepartmentCategories.get(result.getString("abteilunglink.Abteilung_Id")); } else if ("Assoziert".equals(result.getString( "person.Eigenschaft"))) { - depCat = membersAssociatedDepartmentCategories. - get(result.getString( + depCat = membersAssociatedDepartmentCategories.get(result.getString( "abteilunglink.Abteilung_Id")); } @@ -550,17 +551,34 @@ public class PersonImporter extends Program { } } } - + + System.out.println("Contact..."); if (!result.getString("person.Angaben").isEmpty()) { - Contact contact = new Contact(); + System.out.println("Creating contact..."); + Contact contact = new Contact(); + System.out.println("Setting language..."); contact.setLanguage("de"); - contact.setName(String.format("%s-kontakt", person. - getName())); - contact.setTitle(String.format("%s Kontakt", person. - getTitle())); + System.out.println("Setting name..."); + contact.setName(String.format("%s-kontakt", person.getName())); + System.out.println("setting title..."); + contact.setTitle(String.format("%s Kontakt", person.getTitle())); + + System.out.println("Creating contact bundle..."); + contact.setContentSection(contactsSection); + contact.setLifecycle(createLifecycle( + contactLifecycleDefinition)); + GenericContactBundle contactBundle = new GenericContactBundle(contact); + + contactBundle.setDefaultLanguage("de"); + contactBundle.setContentSection(contactsSection); + contactsFolder.addItem(contactBundle); + contactBundle.save(); + + System.out.printf("Setting person to %s...\n", person.getContentBundle().getName()); contact.setPerson(person, "commonContact"); + System.err.println("Done with contact base data."); - + System.err.println("Spliting 'Angaben'..."); final String[] contactData = result.getString("person.Angaben").split( "\n"); @@ -577,7 +595,7 @@ public class PersonImporter extends Program { key = token.substring(0, token.indexOf('=')).trim(); value = token.substring(token.indexOf('=') + 1).trim(); - + if ("Raum_1".equals(key)) { contact.addContactEntry( new GenericContactEntry(contact, @@ -613,16 +631,7 @@ public class PersonImporter extends Program { } } - contact.setAddress(address); - - contact.setContentSection(contactsSection); - contact.setLifecycle(createLifecycle( - contactLifecycleDefinition)); - ContentBundle contactBundle = new ContentBundle(contact); - contactBundle.setDefaultLanguage("de"); - contactBundle.setContentSection(contactsSection); - contactsFolder.addItem(contactBundle); - contactBundle.save(); + contact.setAddress(address); if (homepage != null) { RelatedLink homepageLink; @@ -672,8 +681,7 @@ public class PersonImporter extends Program { path.append("/"); } - final ContentSection _section = (ContentSection) ContentSection. - retrieveApplicationForPath(path.toString()); + final ContentSection _section = (ContentSection) ContentSection.retrieveApplicationForPath(path.toString()); if (_section == null) { throw new DataObjectNotFoundException("Content section not found with path " @@ -779,4 +787,5 @@ public class PersonImporter extends Program { page.setName(resolvedName); page.setTitle(resolvedTitle); } + } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/upgrades/PublicPersonalProfileOwnerAssocUpgrade.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/upgrades/PublicPersonalProfileOwnerAssocUpgrade.java index e7d9c895f..fefb51f20 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/upgrades/PublicPersonalProfileOwnerAssocUpgrade.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/upgrades/PublicPersonalProfileOwnerAssocUpgrade.java @@ -20,7 +20,7 @@ public class PublicPersonalProfileOwnerAssocUpgrade extends AbstractAssocUpgrade @Override protected String getTableName() { - return "ct_public_personal_profile_owner_map.owner_id"; + return "ct_public_personal_profile_owner_map"; } @Override diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources.properties index e8098e31d..75f7e3b23 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources.properties @@ -1098,3 +1098,4 @@ cms.ui.item_search.flat.title=Title cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.type=Type cms.ui.item_search.flatBrowse=Select item +cms.ui.category.undeletable=This category can't be deleted. diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties index a76d605ff..7f714c8e0 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_de.properties @@ -1089,3 +1089,4 @@ cms.ui.item_search.flat.title=Titel cms.ui.item_search.flat.place=Ort cms.ui.item_search.flat.type=Typ cms.ui.item_search.flatBrowse=Item ausw\u00e4hlen +cms.ui.category.undeletable=Diese Kategorie kann nicht gel\u00f6scht werden. diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties index c1fa76778..5d45e2307 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_en_GB.properties @@ -37,3 +37,4 @@ cms.ui.item_search.flat.title=Title cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.type=Type cms.ui.item_search.flatBrowse=Select item +cms.ui.category.undeletable= diff --git a/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties b/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties index dcf4f435c..17e31db4d 100755 --- a/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties +++ b/ccm-cms/src/com/arsdigita/cms/CMSResources_fr.properties @@ -568,3 +568,4 @@ cms.ui.item_search.flat.title=Title cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.type=Type cms.ui.item_search.flatBrowse=Select item +cms.ui.category.undeletable= diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java index 29f45f8f2..38dc03d93 100644 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchFlatBrowsePane.java @@ -13,6 +13,8 @@ import com.arsdigita.bebop.Table; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.parameters.StringParameter; @@ -47,6 +49,7 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, public static final String SEARCHWIDGET_PARAM = "searchWidget"; private final Table resultsTable; private final StringParameter queryParam; + private final Label jsLabel; public ItemSearchFlatBrowsePane(final String name) { @@ -54,15 +57,34 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener, queryParam = new StringParameter(QUERY_PARAM); - final BoxPanel boxPanel = new BoxPanel(BoxPanel.HORIZONTAL); + final BoxPanel boxPanel = new BoxPanel(BoxPanel.HORIZONTAL); boxPanel.add(new Label(GlobalizationUtil.globalize("cms.ui.item_search.flat.filter"))); final TextField filter = new TextField(new StringParameter(QUERY_PARAM)); - boxPanel.add(filter); - add(boxPanel); + boxPanel.add(filter); + jsLabel = new Label("", false); + jsLabel.addPrintListener(new PrintListener() { + + public void prepare(final PrintEvent event) { + final PageState state = event.getPageState(); + final String searchWidget = (String) state.getValue(new StringParameter(SEARCHWIDGET_PARAM)); + ((Label)event.getTarget()).setLabel(String.format( + " ", + filter.getName(), + searchWidget)); + + } + }); + boxPanel.add(jsLabel); + add(boxPanel); resultsTable = new ResultsTable(); add(resultsTable); - + addInitListener(this); addProcessListener(this); } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java index 018f8c3a2..a0efa346e 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchSection.java @@ -156,7 +156,7 @@ public class ItemSearchSection extends FormSection p.setVisibleDefault(m_results, false); p.addGlobalStateParam(new BigDecimalParameter(SINGLE_TYPE_PARAM)); } - + /** * Displays the "keywords" and "content types" widgets */ diff --git a/ccm-cms/src/com/arsdigita/cms/ui/category/CategoryAdminPane.java b/ccm-cms/src/com/arsdigita/cms/ui/category/CategoryAdminPane.java index c7ccd1b9c..39ddc86bd 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/category/CategoryAdminPane.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/category/CategoryAdminPane.java @@ -35,10 +35,15 @@ import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.permissions.PermissionDescriptor; import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.kernel.permissions.PrivilegeDescriptor; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; import com.arsdigita.toolbox.ui.ActionGroup; +import com.arsdigita.toolbox.ui.DataQueryBuilder; import com.arsdigita.toolbox.ui.Section; import com.arsdigita.xml.Element; import java.math.BigDecimal; +import java.util.TooManyListenersException; import org.apache.log4j.Logger; /** @@ -49,16 +54,12 @@ import org.apache.log4j.Logger; */ public final class CategoryAdminPane extends BaseAdminPane { - public static final String CONTEXT_SELECTED="sel_context"; + public static final String CONTEXT_SELECTED = "sel_context"; private static final String DEFAULT_USE_CONTEXT = - CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT; - - private static final Logger s_log = Logger.getLogger - (CategoryAdminPane.class); - + CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT; + private static final Logger s_log = Logger.getLogger(CategoryAdminPane.class); private final SingleSelectionModel m_contextModel; private final Tree m_categoryTree; - private final SingleSelectionModel m_model; private final CategoryRequestLocal m_parent; private final CategoryRequestLocal m_category; @@ -75,7 +76,7 @@ public final class CategoryAdminPane extends BaseAdminPane { List list = new List(new CategoryUseContextModelBuilder()); list.setSelectionModel(m_contextModel); list.addChangeListener(new ContextSelectionListener()); - + /* Category tree section */ m_categoryTree = new BaseTree(new CategoryTreeModelBuilder(m_contextModel)); m_categoryTree.addChangeListener(new SelectionListener()); @@ -84,7 +85,7 @@ public final class CategoryAdminPane extends BaseAdminPane { setSelectionModel(m_model); setSelector(m_categoryTree); - + /* setup use context form */ final Section contextSection = new Section(); contextSection.setHeading(new Label(gz("cms.ui.category.use_contexts"))); @@ -96,10 +97,10 @@ public final class CategoryAdminPane extends BaseAdminPane { ActionLink addContextAction = new ActionLink(new Label(gz("cms.ui.category.add_use_context"))); Form addContextForm = new AddUseContextForm(m_contextModel); getBody().add(addContextForm); - getBody().connect(addContextAction,addContextForm); + getBody().connect(addContextAction, addContextForm); contextGroup.addAction(new VisibilityComponent(addContextAction, SecurityManager.CATEGORY_ADMIN)); - } + } final Section categorySection = new Section(); categorySection.setHeading(new Label(gz("cms.ui.categories"))); @@ -121,9 +122,8 @@ public final class CategoryAdminPane extends BaseAdminPane { setEdit(gz("cms.ui.category.edit"), new CategoryEditForm(m_parent, m_category)); - - setDelete(new DeleteLink(new Label(gz("cms.ui.category.delete"))), - new DeleteForm(new SimpleContainer())); + + setDelete(new DeleteLink(new Label(gz("cms.ui.category.delete"))), new DeleteForm(new SimpleContainer())); setIntroPane(new Label(gz("cms.ui.category.intro"))); setItemPane(new CategoryItemPane(m_model, m_category, @@ -136,7 +136,6 @@ public final class CategoryAdminPane extends BaseAdminPane { } - @Override public void register(final Page page) { super.register(page); @@ -145,63 +144,78 @@ public final class CategoryAdminPane extends BaseAdminPane { } private final class DeleteLink extends ActionLink { + private final Label m_alternativeLabel; DeleteLink(Label label) { super(label); - m_alternativeLabel = new Label("Can't be deleted"); + m_alternativeLabel = new Label(gz("cms.ui.category.undeletable")); } @Override public void generateXML(PageState state, Element parent) { - if (!isVisible(state)) { return; } + if (!isVisible(state)) { + return; + } Category cat = m_category.getCategory(state); String context = getUseContext(state); boolean isDefaultContext = - (context==null) || DEFAULT_USE_CONTEXT.equals(context); - - if (isDefaultContext && cat.isRoot() ) { + (context == null) || DEFAULT_USE_CONTEXT.equals(context); + + + final Session session = SessionManager.getSession(); + final DataCollection collection = session.retrieve("com.arsdigita.london.terms.Term"); + collection.addPath("model.id"); + collection.addPath("model.name"); + + collection.addFilter(String.format("model.id = %s", cat.getID().toString())); + + if ((isDefaultContext && cat.isRoot()) || !collection.isEmpty()) { m_alternativeLabel.generateXML(state, parent); } else { super.generateXML(state, parent); } } + } private final class DeleteForm extends BaseDeleteForm { + DeleteForm(SimpleContainer prompt) { super(prompt); prompt.add(new Label(gz("cms.ui.category.delete_prompt"))); Label catLabel = new Label(); catLabel.addPrintListener(new PrintListener() { - public void prepare(PrintEvent pe) { - Label label = (Label) pe.getTarget(); - Category cat = - m_category.getCategory(pe.getPageState()); - CategoryCollection descendants = cat.getDescendants(); - final long nDescendants = descendants.size() - 1; - descendants.close(); - CategorizedCollection descObjects = - cat.getDescendantObjects(); - final long nDescObjects = descObjects.size(); - descObjects.close(); - StringBuffer sb = new StringBuffer(" "); - if (nDescendants > 0) { - sb.append("This category has "); - sb.append(nDescendants); - sb.append(" descendant category(ies). "); - } - if (nDescObjects > 0) { - sb.append("It has ").append(nDescObjects); - sb.append(" descendant object(s). "); - } - if (nDescendants>0 || nDescObjects>0) { - sb.append("Descendants will be orphaned, if this category is removed."); - } - label.setLabel(sb.toString()); + + public void prepare(PrintEvent pe) { + Label label = (Label) pe.getTarget(); + Category cat = + m_category.getCategory(pe.getPageState()); + CategoryCollection descendants = cat.getDescendants(); + final long nDescendants = descendants.size() - 1; + descendants.close(); + CategorizedCollection descObjects = + cat.getDescendantObjects(); + final long nDescObjects = descObjects.size(); + descObjects.close(); + StringBuffer sb = new StringBuffer(" "); + if (nDescendants > 0) { + sb.append("This category has "); + sb.append(nDescendants); + sb.append(" descendant category(ies). "); } - }); + if (nDescObjects > 0) { + sb.append("It has ").append(nDescObjects); + sb.append(" descendant object(s). "); + } + if (nDescendants > 0 || nDescObjects > 0) { + sb.append("Descendants will be orphaned, if this category is removed."); + } + label.setLabel(sb.toString()); + } + + }); prompt.add(catLabel); } @@ -209,22 +223,21 @@ public final class CategoryAdminPane extends BaseAdminPane { throws FormProcessException { final PageState state = e.getPageState(); final Category category = m_category.getCategory(state); - if (category == null ) { return; } + if (category == null) { + return; + } - PermissionService.assertPermission - (new PermissionDescriptor - (PrivilegeDescriptor.DELETE, - category, - Kernel.getContext().getParty())); + PermissionService.assertPermission(new PermissionDescriptor(PrivilegeDescriptor.DELETE, + category, + Kernel.getContext().getParty())); if (category.isRoot()) { Category root = - Category.getRootForObject(CMS.getContext().getContentSection(), - getUseContext(state)); + Category.getRootForObject(CMS.getContext().getContentSection(), + getUseContext(state)); if (category.equals(root)) { - Category.clearRootForObject - (CMS.getContext().getContentSection(), - getUseContext(state)); + Category.clearRootForObject(CMS.getContext().getContentSection(), + getUseContext(state)); } m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT); } else { @@ -234,9 +247,11 @@ public final class CategoryAdminPane extends BaseAdminPane { category.deleteCategoryAndOrphan(); } + } private final class SelectionRequestLocal extends CategoryRequestLocal { + @Override protected final Object initialValue(final PageState state) { final String id = m_model.getSelectedKey(state).toString(); @@ -247,55 +262,63 @@ public final class CategoryAdminPane extends BaseAdminPane { return new Category(new BigDecimal(id)); } } + } private final class ParentRequestLocal extends CategoryRequestLocal { + @Override protected final Object initialValue(final PageState state) { return m_category.getCategory(state).getDefaultParentCategory(); } + } private final class RootListener implements ActionListener { + public final void actionPerformed(final ActionEvent e) { final PageState state = e.getPageState(); if (!m_model.isSelected(state)) { final Category root = - Category.getRootForObject(CMS.getContext().getContentSection(), - getUseContext(state)); + Category.getRootForObject(CMS.getContext().getContentSection(), + getUseContext(state)); if (root != null) { m_model.setSelectedKey(state, root.getID()); } } } + } private class UseContextSelectionModel extends ParameterSingleSelectionModel { + public UseContextSelectionModel(ParameterModel m) { super(m); } + @Override public Object getSelectedKey(PageState state) { Object val = super.getSelectedKey(state); if (val == null || ((String) val).length() == 0) { val = DEFAULT_USE_CONTEXT; - state.setValue(getStateParameter(),val); + state.setValue(getStateParameter(), val); fireStateChanged(state); } return val; } - } - public String getUseContext(PageState state) { - String selected = (String) m_contextModel.getSelectedKey(state); - return (DEFAULT_USE_CONTEXT).equals(selected) ? - (String) null : selected; + } - public class ContextSelectionListener implements ChangeListener { + public String getUseContext(PageState state) { + String selected = (String) m_contextModel.getSelectedKey(state); + return (DEFAULT_USE_CONTEXT).equals(selected) ? (String) null : selected; + } + + public class ContextSelectionListener implements ChangeListener { + public final void stateChanged(final ChangeEvent e) { - s_log.debug("Selection state changed; I may change " + - "the body's visible pane"); + s_log.debug("Selection state changed; I may change " + "the body's visible pane"); final PageState state = e.getPageState(); @@ -303,8 +326,8 @@ public final class CategoryAdminPane extends BaseAdminPane { if (m_contextModel.isSelected(state)) { final Category root = - Category.getRootForObject(CMS.getContext().getContentSection(), - getUseContext(state)); + Category.getRootForObject(CMS.getContext().getContentSection(), + getUseContext(state)); if (root != null) { m_model.setSelectedKey(state, root.getID()); @@ -313,12 +336,11 @@ public final class CategoryAdminPane extends BaseAdminPane { } if (m_model.isSelected(state)) { - s_log.debug("The selection model is selected; displaying " + - "the item pane"); + s_log.debug("The selection model is selected; displaying " + "the item pane"); getBody().push(state, getItemPane()); } } - } + } }