001 package org.apache.myfaces.tobago.example.reference;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 import org.apache.commons.logging.Log;
021 import org.apache.commons.logging.LogFactory;
022
023 import org.apache.myfaces.tobago.component.UIData;
024
025 import javax.faces.event.ActionEvent;
026 import javax.faces.component.UIComponent;
027 import java.util.List;
028 import java.util.ArrayList;
029
030 public class PopupReferenceController {
031
032 private static final Log LOG = LogFactory.getLog(PopupReferenceController.class);
033
034 private Entry entry;
035
036 private List<Entry> sheet;
037
038
039 public PopupReferenceController() {
040 sheet = new ArrayList<Entry>();
041 for (int i = 0; i < 10; i++) {
042 Entry tmp = new Entry();
043 tmp.setColumn1("cell__1__" + i);
044 tmp.setColumn2("cell_2_" + i);
045 tmp.setColumn3("cell_3_" + i);
046 sheet.add(tmp);
047 }
048 }
049
050 public void selectEntry(ActionEvent event) {
051 UIComponent component = event.getComponent();
052 while (!(component instanceof UIData)) {
053 component = component.getParent();
054 }
055
056 UIData sheet = (UIData) component;
057 entry = (Entry) sheet.getRowData();
058 LOG.info("entry = \"" + entry.getColumn1() + "\"");
059 }
060
061 public void saveChanges(ActionEvent event) {
062 LOG.info("saveChanges()");
063 // nothing to do here
064 }
065
066
067 public List<Entry> getSheet() {
068 return sheet;
069 }
070
071 public Entry getEntry() {
072 return entry;
073 }
074
075 public void setEntry(Entry entry) {
076 this.entry = entry;
077 }
078
079 public static class Entry{
080 private String column1;
081 private String column2;
082 private String column3;
083
084 public String getColumn1() {
085 return column1;
086 }
087
088 public void setColumn1(String column1) {
089 this.column1 = column1;
090 }
091
092 public String getColumn2() {
093 return column2;
094 }
095
096 public void setColumn2(String column2) {
097 this.column2 = column2;
098 }
099
100 public String getColumn3() {
101 return column3;
102 }
103
104 public void setColumn3(String column3) {
105 this.column3 = column3;
106 }
107 }
108 }