diff --git a/ccm-cms/src/com/arsdigita/cms/ui/IdSearchResultTable.java b/ccm-cms/src/com/arsdigita/cms/ui/IdSearchResultTable.java new file mode 100644 index 000000000..efe35d9ec --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/ui/IdSearchResultTable.java @@ -0,0 +1,215 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.arsdigita.cms.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Link; +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.form.TextField; +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.ContentItem; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.dispatcher.ItemResolver; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.OID; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * + * @author koalamann + */ +public class IdSearchResultTable extends Table { + + private TextField textField; + protected Label label; + + public IdSearchResultTable(TextField textfield) { + super(); + this.textField = textfield; + label = new Label("bla"); + if (textfield == null) { + setEmptyView(new Label("...")); + } else { + setEmptyView(new Label("......")); + } + + final TableColumnModel columnModel = getColumnModel(); + columnModel.add(new TableColumn( + 0, + new Label("Result:"))); + + columnModel.get(0).setCellRenderer( + new TableCellRenderer() { + @Override + public Component getComponent(final Table table, + final PageState state, + final Object value, + final boolean isSelected, + final Object key, + final int row, + final int column) { + + String str = (String) textField.getValue(state); + + if (isInteger(str)) { + int number = Integer.parseInt(str); + BigDecimal id = new BigDecimal(number); + + try { + ContentItem item = (ContentItem) DomainObjectFactory + .newInstance(new OID( + ContentItem.BASE_DATA_OBJECT_TYPE, + id)); + + ContentSection section = item.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + +// if (displayName.length() > 20) { +// displayName = displayName.substring(0, 15); +// } + Link link = new Link( + item.getDisplayName(), + resolver.generateItemURL( + state, + (item.getDraftVersion()), + section, + (item.getDraftVersion()).getVersion())); + + return link; + } catch (DataObjectNotFoundException e) { + return new Label("Error: Could not find item with the id " + number); + } + + } else { + return new Label("Error: the item-id has to be numeric"); + } + + } + }); + + addTableActionListener(new TableActionListener() { + @Override + public void cellSelected(final TableActionEvent event) { + //ToDo + } + + @Override + public void headSelected(final TableActionEvent event) { + //Nothing + } + }); + + setModelBuilder(new IdSearchResultTableModelBuilder()); + + } + + private class IdSearchResultTableModelBuilder extends LockableImpl + implements TableModelBuilder { + + @Override + public TableModel makeModel(final Table table, + final PageState state) { + table.getRowSelectionModel().clearSelection(state); + + return new IdSearchResultTableModel(state); + } + + } + + private class IdSearchResultTableModel implements TableModel { + +// private final List domains; + private int index = -1; + + public IdSearchResultTableModel(final PageState state) { +// LOGGER.debug("Creating DomainsTableModel"); + final String filterTerm = (String) textField.getValue(state); + if (filterTerm == null) { + label = new Label("filterTerm is null"); + } else { + + if (filterTerm.isEmpty()) { + //wenn keine ID eingegeben + label = new Label("bitte korrekte ID eingeben"); + } else { + label = new Label(filterTerm); + } + } + } + + @Override + public int getColumnCount() { + return 1; + } + + @Override + public boolean nextRow() { + index++; + if (index >= 1) { + return false; + } else { + return true; + } + } + + @Override + public Object getElementAt(final int columnIndex) { + +// final Domain domain = domains.get(index); +// if (columnIndex == 0) { + return label; +// } else { +// return new Label("getElementAtWrongColumnindex"); +// } + } + + @Override + public Object getKeyAt(final int columnIndex) { + return 1; + } + + } + + /* + * method to check if a string is an Integer + * + * source: http://stackoverflow.com/questions/237159/whats-the-best-way-to-check-to-see-if-a-string-represents-an-integer-in-java + */ + public static boolean isInteger(String str) { + if (str == null) { + return false; + } + int length = str.length(); + if (length == 0) { + return false; + } + int i = 0; + if (str.charAt(0) == '-') { + if (length == 1) { + return false; + } + i = 1; + } + for (; i < length; i++) { + char c = str.charAt(i); + if (c < '0' || c > '9') { + return false; + } + } + return true; + } + +} diff --git a/ccm-cms/src/com/arsdigita/cms/ui/IdSearchTab.java b/ccm-cms/src/com/arsdigita/cms/ui/IdSearchTab.java new file mode 100644 index 000000000..70f427eb9 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/ui/IdSearchTab.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved. + * + * 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.ui; + +import com.arsdigita.bebop.BoxPanel; +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.SegmentedPanel; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.toolbox.ui.LayoutPanel; + +/** + * A wrapper around the {@link ItemSearchSection} which embedds the form section + * in a form. + * + * @author Stanislav Freidin (sfreidin@arsdigita.com) + * @version $Id: ItemSearch.java 1940 2009-05-29 07:15:05Z terry $ + */ +public class IdSearchTab extends LayoutPanel { + + private final Form filterform; + private final Label formHeader; + private final TextField textField; + private final BoxPanel idSearchResultTablePanel; + + + public IdSearchTab(String name) { + super(); + + filterform = new Form("IdSearchForm"); + formHeader = new Label("Item-id:"); + textField = new TextField("IdFeld"); +// textField.setHint("An ID has 4 digits"); + textField.addValidationListener(new NotNullValidationListener()); + + filterform.add(textField); + filterform.add(new Submit("search")); + + final SegmentedPanel left = new SegmentedPanel(); + left.addSegment(formHeader, filterform); + + setLeft(left); + + final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL); + + final IdSearchResultTable idSearchResultTable = new IdSearchResultTable( + textField); + idSearchResultTable.setStyleAttr("min-width: 30em;"); + idSearchResultTablePanel = new BoxPanel(BoxPanel.VERTICAL); + idSearchResultTablePanel.add(idSearchResultTable); + body.add(idSearchResultTablePanel); + + setBody(body); + + } + +} diff --git a/ccm-cms/src/com/arsdigita/cms/ui/contentcenter/MainPage.java b/ccm-cms/src/com/arsdigita/cms/ui/contentcenter/MainPage.java index 70dc25fe7..779487c27 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/contentcenter/MainPage.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/contentcenter/MainPage.java @@ -26,6 +26,7 @@ import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ui.CMSApplicationPage; import com.arsdigita.cms.ui.GlobalNavigation; +import com.arsdigita.cms.ui.IdSearchTab; import com.arsdigita.cms.ui.ItemSearch; import com.arsdigita.cms.ui.WorkspaceContextBar; import com.arsdigita.cms.util.GlobalizationUtil; @@ -67,6 +68,7 @@ public class MainPage extends CMSApplicationPage implements ActionListener { private TasksPanel m_tasks; private ItemSearch m_search; + private IdSearchTab m_IdSearch; private ACSObjectSelectionModel m_typeSel; private ACSObjectSelectionModel m_sectionSel; @@ -109,7 +111,8 @@ public class MainPage extends CMSApplicationPage implements ActionListener { m_tasks = getTasksPane(m_typeSel, m_sectionSel); m_search = getSearchPane(); - + m_IdSearch = getIdSearchPane(); + m_tabbedPane = createTabbedPane(); m_tabbedPane.setIdAttr("page-body"); add(m_tabbedPane); @@ -141,6 +144,14 @@ public class MainPage extends CMSApplicationPage implements ActionListener { return m_search; } + + protected IdSearchTab getIdSearchPane(){ + if (m_IdSearch == null) { + m_IdSearch = new IdSearchTab("idsearch"); + } + + return m_IdSearch; + } /** * Created the TabbedPane to use for this page. Sets the class @@ -159,6 +170,8 @@ public class MainPage extends CMSApplicationPage implements ActionListener { .globalize("cms.ui.contentcenter.mainpage.taskssections")); Label searchLabel = new Label(GlobalizationUtil .globalize("cms.ui.contentcenter.mainpage.search")); + Label IdsearchLabel = new Label("ID Search"); + addToPane(tabbedPane, taskLabel, getTasksPane(m_typeSel, m_sectionSel)); @@ -167,6 +180,10 @@ public class MainPage extends CMSApplicationPage implements ActionListener { new Label(GlobalizationUtil.globalize( "cms.ui.contentcenter.mainpage.search")), getSearchPane()); + addToPane(tabbedPane, + IdsearchLabel, + getIdSearchPane()); + tabbedPane.addActionListener(this); return tabbedPane; } @@ -217,7 +234,9 @@ public class MainPage extends CMSApplicationPage implements ActionListener { m_tasks.reset(state); } else if ( pane == m_search ) { m_search.reset(state); - } + } else if ( pane == m_IdSearch ) { + m_IdSearch.reset(state); + } } }