- CategoryAdminPane zeigt den Link zum Löschen von Kategorien nicht mehr für Kategorien an, die gleichzeitig Terms sind.

- Formatierungen und Doku


git-svn-id: https://svn.libreccm.org/ccm/trunk@1711 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2012-06-15 13:53:07 +00:00
parent 5f507521fc
commit e56909c9cc
9 changed files with 193 additions and 136 deletions

View File

@ -8,17 +8,19 @@ import com.arsdigita.cms.Folder;
import com.arsdigita.cms.contentassets.RelatedLink; import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.contenttypes.Address; import com.arsdigita.cms.contenttypes.Address;
import com.arsdigita.cms.contenttypes.Contact; import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.GenericContactBundle;
import com.arsdigita.cms.contenttypes.GenericContactEntry; import com.arsdigita.cms.contenttypes.GenericContactEntry;
import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.GenericPersonBundle;
import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.contenttypes.Link;
import com.arsdigita.cms.contenttypes.SciMember; import com.arsdigita.cms.contenttypes.SciMember;
import com.arsdigita.cms.lifecycle.Lifecycle; import com.arsdigita.cms.lifecycle.Lifecycle;
import com.arsdigita.cms.lifecycle.LifecycleDefinition; import com.arsdigita.cms.lifecycle.LifecycleDefinition;
import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection; import com.arsdigita.cms.lifecycle.LifecycleDefinitionCollection;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.packaging.Program;
import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.TransactionContext; import com.arsdigita.persistence.TransactionContext;
import com.arsdigita.util.cmd.Program;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -68,7 +70,7 @@ public class PersonImporter extends Program {
private Folder addressFolder; private Folder addressFolder;
private Category membersActiveCategory; private Category membersActiveCategory;
private Category membersFormerCategory; private Category membersFormerCategory;
private Category membersAssociatedCategory; //private Category membersAssociatedCategory;
//Department key -> category //Department key -> category
private final Map<String, Category> membersActiveDepartmentCategories = private final Map<String, Category> membersActiveDepartmentCategories =
new TreeMap<String, Category>(); new TreeMap<String, Category>();
@ -149,8 +151,7 @@ public class PersonImporter extends Program {
addressSection = getContentSection((config.getProperty( addressSection = getContentSection((config.getProperty(
"address.contentsection"))); "address.contentsection")));
LifecycleDefinitionCollection lifecycles = membersSection. LifecycleDefinitionCollection lifecycles = membersSection.getLifecycleDefinitions();
getLifecycleDefinitions();
while (lifecycles.next()) { while (lifecycles.next()) {
membersLifecycle = lifecycles.getLifecycleDefinition(); membersLifecycle = lifecycles.getLifecycleDefinition();
} }
@ -203,9 +204,9 @@ public class PersonImporter extends Program {
"members.active.category"))); "members.active.category")));
membersFormerCategory = new Category(new BigDecimal(config.getProperty( membersFormerCategory = new Category(new BigDecimal(config.getProperty(
"members.former.category"))); "members.former.category")));
membersAssociatedCategory = new Category(new BigDecimal(config. // membersAssociatedCategory = new Category(new BigDecimal(config.
getProperty( // getProperty(
"members.associated.category"))); // "members.associated.category")));
//Get department ids from DaBIn DB //Get department ids from DaBIn DB
//Create connection to the DaBIn MySQL database //Create connection to the DaBIn MySQL database
@ -304,16 +305,13 @@ public class PersonImporter extends Program {
System.out.println("Configuration values:"); System.out.println("Configuration values:");
System.out.println("---------------------"); System.out.println("---------------------");
System.out.printf("membersSection = %s\n", membersSection. System.out.printf("membersSection = %s\n", membersSection.getName());
getName());
System.out.printf("membersContactsSection = %s\n", System.out.printf("membersContactsSection = %s\n",
membersContactsSection.getName()); membersContactsSection.getName());
System.out.printf("authorsSection = %s\n", authorsSection. System.out.printf("authorsSection = %s\n", authorsSection.getName());
getName());
System.out.printf("authorsContactsSection = %s\n", System.out.printf("authorsContactsSection = %s\n",
authorsContactsSection.getName()); authorsContactsSection.getName());
System.out.printf("personsSection = %s\n", personsSection. System.out.printf("personsSection = %s\n", personsSection.getName());
getName());
System.out.printf("personsContactsSection = %s\n", System.out.printf("personsContactsSection = %s\n",
personsContactsSection.getName()); personsContactsSection.getName());
System.out.println(""); System.out.println("");
@ -336,8 +334,8 @@ public class PersonImporter extends Program {
membersActiveCategory.getName()); membersActiveCategory.getName());
System.out.printf("membersFormerCategory = %s\n", System.out.printf("membersFormerCategory = %s\n",
membersFormerCategory.getName()); membersFormerCategory.getName());
System.out.printf("membersAssociatedCategory = %s\n", // System.out.printf("membersAssociatedCategory = %s\n",
membersAssociatedCategory.getName()); // membersAssociatedCategory.getName());
System.out.println( System.out.println(
"Categories for active members in the departments " "Categories for active members in the departments "
@ -422,12 +420,14 @@ public class PersonImporter extends Program {
address.setCity(config.getProperty("address.city")); address.setCity(config.getProperty("address.city"));
address.setIsoCountryCode(config.getProperty("address.country")); address.setIsoCountryCode(config.getProperty("address.country"));
address.setLanguage("de"); address.setLanguage("de");
address.save();
final ContentBundle addressBundle = new ContentBundle(address); final ContentBundle addressBundle = new ContentBundle(address);
addressBundle.setDefaultLanguage("de"); addressBundle.setDefaultLanguage("de");
address.setContentSection(addressSection); address.setContentSection(addressSection);
addressBundle.setContentSection(addressSection); addressBundle.setContentSection(addressSection);
addressBundle.save();
addressFolder.addItem(addressBundle); addressFolder.addItem(addressBundle);
try { try {
@ -461,6 +461,7 @@ public class PersonImporter extends Program {
LifecycleDefinition lifecycleDefinition = null; LifecycleDefinition lifecycleDefinition = null;
LifecycleDefinition contactLifecycleDefinition = null; LifecycleDefinition contactLifecycleDefinition = null;
Category category = null; Category category = null;
System.out.println("Eigenschaft...");
if ("Aktiv".equals(result.getString("person.Eigenschaft"))) { if ("Aktiv".equals(result.getString("person.Eigenschaft"))) {
person = new SciMember(); person = new SciMember();
section = membersSection; section = membersSection;
@ -482,23 +483,25 @@ public class PersonImporter extends Program {
lifecycleDefinition = membersLifecycle; lifecycleDefinition = membersLifecycle;
contactLifecycleDefinition = membersContactsLifecycle; contactLifecycleDefinition = membersContactsLifecycle;
category = membersFormerCategory; 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.setSurname(result.getString("person.Name"));
person.setGivenName(result.getString("person.Vorname")); person.setGivenName(result.getString("person.Vorname"));
person.setTitlePre(result.getString("person.Anrede")); person.setTitlePre(result.getString("person.Anrede"));
person.setDabinId(result.getInt("person.Person_Id")); //person.setDabinId(result.getInt("person.Person_Id"));
person.setLanguage("de"); person.setLanguage("de");
person.setContentSection(section); person.setContentSection(section);
person.setLifecycle(createLifecycle(lifecycleDefinition)); person.setLifecycle(createLifecycle(lifecycleDefinition));
@ -506,7 +509,7 @@ public class PersonImporter extends Program {
resolveDuplicateNameAndTitle(person, folder); resolveDuplicateNameAndTitle(person, folder);
ContentBundle personBundle = new ContentBundle(person); GenericPersonBundle personBundle = new GenericPersonBundle(person);
personBundle.setDefaultLanguage("de"); personBundle.setDefaultLanguage("de");
personBundle.setContentSection(section); personBundle.setContentSection(section);
folder.addItem(personBundle); folder.addItem(personBundle);
@ -519,6 +522,7 @@ public class PersonImporter extends Program {
category.addChild(personBundle); category.addChild(personBundle);
} }
System.out.println("Department assoc...");
if ("Aktiv".equals(result.getString("person.Eigenschaft")) if ("Aktiv".equals(result.getString("person.Eigenschaft"))
|| "Ehemalig".equals(result.getString( || "Ehemalig".equals(result.getString(
"person.Eigenschaft")) "person.Eigenschaft"))
@ -531,17 +535,14 @@ public class PersonImporter extends Program {
if ("Aktiv".equals(result.getString( if ("Aktiv".equals(result.getString(
"person.Eigenschaft"))) { "person.Eigenschaft"))) {
depCat = depCat =
membersActiveDepartmentCategories.get(result. membersActiveDepartmentCategories.get(result.getString("abteilunglink.Abteilung_Id"));
getString("abteilunglink.Abteilung_Id"));
} else if ("Ehemalig".equals(result.getString( } else if ("Ehemalig".equals(result.getString(
"person.Eigenschaft"))) { "person.Eigenschaft"))) {
depCat = depCat =
membersFormerDepartmentCategories.get(result. membersFormerDepartmentCategories.get(result.getString("abteilunglink.Abteilung_Id"));
getString("abteilunglink.Abteilung_Id"));
} else if ("Assoziert".equals(result.getString( } else if ("Assoziert".equals(result.getString(
"person.Eigenschaft"))) { "person.Eigenschaft"))) {
depCat = membersAssociatedDepartmentCategories. depCat = membersAssociatedDepartmentCategories.get(result.getString(
get(result.getString(
"abteilunglink.Abteilung_Id")); "abteilunglink.Abteilung_Id"));
} }
@ -551,16 +552,33 @@ public class PersonImporter extends Program {
} }
} }
System.out.println("Contact...");
if (!result.getString("person.Angaben").isEmpty()) { if (!result.getString("person.Angaben").isEmpty()) {
System.out.println("Creating contact...");
Contact contact = new Contact(); Contact contact = new Contact();
System.out.println("Setting language...");
contact.setLanguage("de"); contact.setLanguage("de");
contact.setName(String.format("%s-kontakt", person. System.out.println("Setting name...");
getName())); contact.setName(String.format("%s-kontakt", person.getName()));
contact.setTitle(String.format("%s Kontakt", person. System.out.println("setting title...");
getTitle())); 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"); contact.setPerson(person, "commonContact");
System.err.println("Done with contact base data.");
System.err.println("Spliting 'Angaben'...");
final String[] contactData = final String[] contactData =
result.getString("person.Angaben").split( result.getString("person.Angaben").split(
"\n"); "\n");
@ -615,15 +633,6 @@ public class PersonImporter extends Program {
contact.setAddress(address); 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();
if (homepage != null) { if (homepage != null) {
RelatedLink homepageLink; RelatedLink homepageLink;
homepageLink = new RelatedLink(); homepageLink = new RelatedLink();
@ -672,8 +681,7 @@ public class PersonImporter extends Program {
path.append("/"); path.append("/");
} }
final ContentSection _section = (ContentSection) ContentSection. final ContentSection _section = (ContentSection) ContentSection.retrieveApplicationForPath(path.toString());
retrieveApplicationForPath(path.toString());
if (_section == null) { if (_section == null) {
throw new DataObjectNotFoundException("Content section not found with path " throw new DataObjectNotFoundException("Content section not found with path "
@ -779,4 +787,5 @@ public class PersonImporter extends Program {
page.setName(resolvedName); page.setName(resolvedName);
page.setTitle(resolvedTitle); page.setTitle(resolvedTitle);
} }
} }

View File

@ -20,7 +20,7 @@ public class PublicPersonalProfileOwnerAssocUpgrade extends AbstractAssocUpgrade
@Override @Override
protected String getTableName() { protected String getTableName() {
return "ct_public_personal_profile_owner_map.owner_id"; return "ct_public_personal_profile_owner_map";
} }
@Override @Override

View File

@ -1098,3 +1098,4 @@ cms.ui.item_search.flat.title=Title
cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.place=Place
cms.ui.item_search.flat.type=Type cms.ui.item_search.flat.type=Type
cms.ui.item_search.flatBrowse=Select item cms.ui.item_search.flatBrowse=Select item
cms.ui.category.undeletable=This category can't be deleted.

View File

@ -1089,3 +1089,4 @@ cms.ui.item_search.flat.title=Titel
cms.ui.item_search.flat.place=Ort cms.ui.item_search.flat.place=Ort
cms.ui.item_search.flat.type=Typ cms.ui.item_search.flat.type=Typ
cms.ui.item_search.flatBrowse=Item ausw\u00e4hlen cms.ui.item_search.flatBrowse=Item ausw\u00e4hlen
cms.ui.category.undeletable=Diese Kategorie kann nicht gel\u00f6scht werden.

View File

@ -37,3 +37,4 @@ cms.ui.item_search.flat.title=Title
cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.place=Place
cms.ui.item_search.flat.type=Type cms.ui.item_search.flat.type=Type
cms.ui.item_search.flatBrowse=Select item cms.ui.item_search.flatBrowse=Select item
cms.ui.category.undeletable=

View File

@ -568,3 +568,4 @@ cms.ui.item_search.flat.title=Title
cms.ui.item_search.flat.place=Place cms.ui.item_search.flat.place=Place
cms.ui.item_search.flat.type=Type cms.ui.item_search.flat.type=Type
cms.ui.item_search.flatBrowse=Select item cms.ui.item_search.flatBrowse=Select item
cms.ui.category.undeletable=

View File

@ -13,6 +13,8 @@ import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; 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.form.TextField;
import com.arsdigita.bebop.parameters.BigDecimalParameter; import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
@ -47,6 +49,7 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
public static final String SEARCHWIDGET_PARAM = "searchWidget"; public static final String SEARCHWIDGET_PARAM = "searchWidget";
private final Table resultsTable; private final Table resultsTable;
private final StringParameter queryParam; private final StringParameter queryParam;
private final Label jsLabel;
public ItemSearchFlatBrowsePane(final String name) { public ItemSearchFlatBrowsePane(final String name) {
@ -58,6 +61,25 @@ public class ItemSearchFlatBrowsePane extends Form implements FormInitListener,
boxPanel.add(new Label(GlobalizationUtil.globalize("cms.ui.item_search.flat.filter"))); boxPanel.add(new Label(GlobalizationUtil.globalize("cms.ui.item_search.flat.filter")));
final TextField filter = new TextField(new StringParameter(QUERY_PARAM)); final TextField filter = new TextField(new StringParameter(QUERY_PARAM));
boxPanel.add(filter); 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(
" <script language=javascript type=\"text/javascript\">"
+ "<!--"
+ "alert(\"test\")"
+ "self.elements['%s'].value='test';"//window.opener.document.%s.value;"
+ "-->"
+ "</script> ",
filter.getName(),
searchWidget));
}
});
boxPanel.add(jsLabel);
add(boxPanel); add(boxPanel);
resultsTable = new ResultsTable(); resultsTable = new ResultsTable();

View File

@ -35,10 +35,15 @@ import com.arsdigita.kernel.Kernel;
import com.arsdigita.kernel.permissions.PermissionDescriptor; import com.arsdigita.kernel.permissions.PermissionDescriptor;
import com.arsdigita.kernel.permissions.PermissionService; import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.kernel.permissions.PrivilegeDescriptor; 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.ActionGroup;
import com.arsdigita.toolbox.ui.DataQueryBuilder;
import com.arsdigita.toolbox.ui.Section; import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.TooManyListenersException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
@ -49,16 +54,12 @@ import org.apache.log4j.Logger;
*/ */
public final class CategoryAdminPane extends BaseAdminPane { 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 = private static final String DEFAULT_USE_CONTEXT =
CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT; CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT;
private static final Logger s_log = Logger.getLogger(CategoryAdminPane.class);
private static final Logger s_log = Logger.getLogger
(CategoryAdminPane.class);
private final SingleSelectionModel m_contextModel; private final SingleSelectionModel m_contextModel;
private final Tree m_categoryTree; private final Tree m_categoryTree;
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
private final CategoryRequestLocal m_parent; private final CategoryRequestLocal m_parent;
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
@ -96,7 +97,7 @@ public final class CategoryAdminPane extends BaseAdminPane {
ActionLink addContextAction = new ActionLink(new Label(gz("cms.ui.category.add_use_context"))); ActionLink addContextAction = new ActionLink(new Label(gz("cms.ui.category.add_use_context")));
Form addContextForm = new AddUseContextForm(m_contextModel); Form addContextForm = new AddUseContextForm(m_contextModel);
getBody().add(addContextForm); getBody().add(addContextForm);
getBody().connect(addContextAction,addContextForm); getBody().connect(addContextAction, addContextForm);
contextGroup.addAction(new VisibilityComponent(addContextAction, contextGroup.addAction(new VisibilityComponent(addContextAction,
SecurityManager.CATEGORY_ADMIN)); SecurityManager.CATEGORY_ADMIN));
} }
@ -122,8 +123,7 @@ public final class CategoryAdminPane extends BaseAdminPane {
setEdit(gz("cms.ui.category.edit"), setEdit(gz("cms.ui.category.edit"),
new CategoryEditForm(m_parent, m_category)); new CategoryEditForm(m_parent, m_category));
setDelete(new DeleteLink(new Label(gz("cms.ui.category.delete"))), setDelete(new DeleteLink(new Label(gz("cms.ui.category.delete"))), new DeleteForm(new SimpleContainer()));
new DeleteForm(new SimpleContainer()));
setIntroPane(new Label(gz("cms.ui.category.intro"))); setIntroPane(new Label(gz("cms.ui.category.intro")));
setItemPane(new CategoryItemPane(m_model, m_category, setItemPane(new CategoryItemPane(m_model, m_category,
@ -136,7 +136,6 @@ public final class CategoryAdminPane extends BaseAdminPane {
} }
@Override @Override
public void register(final Page page) { public void register(final Page page) {
super.register(page); super.register(page);
@ -145,63 +144,78 @@ public final class CategoryAdminPane extends BaseAdminPane {
} }
private final class DeleteLink extends ActionLink { private final class DeleteLink extends ActionLink {
private final Label m_alternativeLabel; private final Label m_alternativeLabel;
DeleteLink(Label label) { DeleteLink(Label label) {
super(label); super(label);
m_alternativeLabel = new Label("Can't be deleted"); m_alternativeLabel = new Label(gz("cms.ui.category.undeletable"));
} }
@Override @Override
public void generateXML(PageState state, Element parent) { public void generateXML(PageState state, Element parent) {
if (!isVisible(state)) { return; } if (!isVisible(state)) {
return;
}
Category cat = m_category.getCategory(state); Category cat = m_category.getCategory(state);
String context = getUseContext(state); String context = getUseContext(state);
boolean isDefaultContext = boolean isDefaultContext =
(context==null) || DEFAULT_USE_CONTEXT.equals(context); (context == null) || DEFAULT_USE_CONTEXT.equals(context);
if (isDefaultContext && cat.isRoot() ) {
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); m_alternativeLabel.generateXML(state, parent);
} else { } else {
super.generateXML(state, parent); super.generateXML(state, parent);
} }
} }
} }
private final class DeleteForm extends BaseDeleteForm { private final class DeleteForm extends BaseDeleteForm {
DeleteForm(SimpleContainer prompt) { DeleteForm(SimpleContainer prompt) {
super(prompt); super(prompt);
prompt.add(new Label(gz("cms.ui.category.delete_prompt"))); prompt.add(new Label(gz("cms.ui.category.delete_prompt")));
Label catLabel = new Label(); Label catLabel = new Label();
catLabel.addPrintListener(new PrintListener() { catLabel.addPrintListener(new PrintListener() {
public void prepare(PrintEvent pe) {
Label label = (Label) pe.getTarget(); public void prepare(PrintEvent pe) {
Category cat = Label label = (Label) pe.getTarget();
m_category.getCategory(pe.getPageState()); Category cat =
CategoryCollection descendants = cat.getDescendants(); m_category.getCategory(pe.getPageState());
final long nDescendants = descendants.size() - 1; CategoryCollection descendants = cat.getDescendants();
descendants.close(); final long nDescendants = descendants.size() - 1;
CategorizedCollection descObjects = descendants.close();
cat.getDescendantObjects(); CategorizedCollection descObjects =
final long nDescObjects = descObjects.size(); cat.getDescendantObjects();
descObjects.close(); final long nDescObjects = descObjects.size();
StringBuffer sb = new StringBuffer(" "); descObjects.close();
if (nDescendants > 0) { StringBuffer sb = new StringBuffer(" ");
sb.append("This category has "); if (nDescendants > 0) {
sb.append(nDescendants); sb.append("This category has ");
sb.append(" descendant category(ies). "); 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());
} }
}); 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); prompt.add(catLabel);
} }
@ -209,22 +223,21 @@ public final class CategoryAdminPane extends BaseAdminPane {
throws FormProcessException { throws FormProcessException {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
if (category == null ) { return; } if (category == null) {
return;
}
PermissionService.assertPermission PermissionService.assertPermission(new PermissionDescriptor(PrivilegeDescriptor.DELETE,
(new PermissionDescriptor category,
(PrivilegeDescriptor.DELETE, Kernel.getContext().getParty()));
category,
Kernel.getContext().getParty()));
if (category.isRoot()) { if (category.isRoot()) {
Category root = Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); getUseContext(state));
if (category.equals(root)) { if (category.equals(root)) {
Category.clearRootForObject Category.clearRootForObject(CMS.getContext().getContentSection(),
(CMS.getContext().getContentSection(), getUseContext(state));
getUseContext(state));
} }
m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT); m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT);
} else { } else {
@ -234,9 +247,11 @@ public final class CategoryAdminPane extends BaseAdminPane {
category.deleteCategoryAndOrphan(); category.deleteCategoryAndOrphan();
} }
} }
private final class SelectionRequestLocal extends CategoryRequestLocal { private final class SelectionRequestLocal extends CategoryRequestLocal {
@Override @Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
final String id = m_model.getSelectedKey(state).toString(); final String id = m_model.getSelectedKey(state).toString();
@ -247,55 +262,63 @@ public final class CategoryAdminPane extends BaseAdminPane {
return new Category(new BigDecimal(id)); return new Category(new BigDecimal(id));
} }
} }
} }
private final class ParentRequestLocal extends CategoryRequestLocal { private final class ParentRequestLocal extends CategoryRequestLocal {
@Override @Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
return m_category.getCategory(state).getDefaultParentCategory(); return m_category.getCategory(state).getDefaultParentCategory();
} }
} }
private final class RootListener implements ActionListener { private final class RootListener implements ActionListener {
public final void actionPerformed(final ActionEvent e) { public final void actionPerformed(final ActionEvent e) {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
if (!m_model.isSelected(state)) { if (!m_model.isSelected(state)) {
final Category root = final Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); getUseContext(state));
if (root != null) { if (root != null) {
m_model.setSelectedKey(state, root.getID()); m_model.setSelectedKey(state, root.getID());
} }
} }
} }
} }
private class UseContextSelectionModel extends ParameterSingleSelectionModel { private class UseContextSelectionModel extends ParameterSingleSelectionModel {
public UseContextSelectionModel(ParameterModel m) { public UseContextSelectionModel(ParameterModel m) {
super(m); super(m);
} }
@Override @Override
public Object getSelectedKey(PageState state) { public Object getSelectedKey(PageState state) {
Object val = super.getSelectedKey(state); Object val = super.getSelectedKey(state);
if (val == null || ((String) val).length() == 0) { if (val == null || ((String) val).length() == 0) {
val = DEFAULT_USE_CONTEXT; val = DEFAULT_USE_CONTEXT;
state.setValue(getStateParameter(),val); state.setValue(getStateParameter(), val);
fireStateChanged(state); fireStateChanged(state);
} }
return val; 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) { public final void stateChanged(final ChangeEvent e) {
s_log.debug("Selection state changed; I may change " + s_log.debug("Selection state changed; I may change " + "the body's visible pane");
"the body's visible pane");
final PageState state = e.getPageState(); final PageState state = e.getPageState();
@ -303,8 +326,8 @@ public final class CategoryAdminPane extends BaseAdminPane {
if (m_contextModel.isSelected(state)) { if (m_contextModel.isSelected(state)) {
final Category root = final Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); getUseContext(state));
if (root != null) { if (root != null) {
m_model.setSelectedKey(state, root.getID()); m_model.setSelectedKey(state, root.getID());
@ -313,12 +336,11 @@ public final class CategoryAdminPane extends BaseAdminPane {
} }
if (m_model.isSelected(state)) { if (m_model.isSelected(state)) {
s_log.debug("The selection model is selected; displaying " + s_log.debug("The selection model is selected; displaying " + "the item pane");
"the item pane");
getBody().push(state, getItemPane()); getBody().push(state, getItemPane());
} }
} }
}
}
} }