001: /*
002: * Copyright 2006-2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
007: *
008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
010: * the license for the specific language governing your rights and limitations.
011: *
012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
013: */
014: package org.pentaho.reportdesigner.crm.report.datasetplugin.staticfactory;
015:
016: import org.jetbrains.annotations.NonNls;
017: import org.jetbrains.annotations.NotNull;
018: import org.jetbrains.annotations.Nullable;
019: import org.pentaho.reportdesigner.crm.report.datasetplugin.properties.PropertyInfo;
020: import org.pentaho.reportdesigner.lib.client.i18n.TranslationManager;
021:
022: import javax.swing.table.AbstractTableModel;
023: import java.util.ArrayList;
024: import java.util.HashSet;
025: import java.util.logging.Level;
026: import java.util.logging.Logger;
027:
028: /**
029: * User: Martin
030: * Date: 16.02.2006
031: * Time: 16:16:41
032: */
033: public class ParametersTableModel extends AbstractTableModel {
034: @NonNls
035: @NotNull
036: private static final Logger LOG = Logger
037: .getLogger(ParametersTableModel.class.getName());
038:
039: @NotNull
040: private ArrayList<PropertyInfo> propertyInfos;
041:
042: public ParametersTableModel(@NotNull
043: ArrayList<PropertyInfo> propertyInfos) {
044: this .propertyInfos = propertyInfos;
045: }
046:
047: public int getRowCount() {
048: return propertyInfos.size();
049: }
050:
051: public int getColumnCount() {
052: return 2;
053: }
054:
055: @NotNull
056: public ArrayList<PropertyInfo> getProperties() {
057: return new ArrayList<PropertyInfo>(propertyInfos);
058: }
059:
060: @Nullable
061: public PropertyInfo getProperty(int index) {
062: try {
063: return propertyInfos.get(index);
064: } catch (Exception e) {
065: if (ParametersTableModel.LOG.isLoggable(Level.FINE))
066: ParametersTableModel.LOG.log(Level.FINE,
067: "PropertiesTableModel.getProperty ", e);
068: }
069: return null;
070: }
071:
072: public void addProperty(@NotNull
073: PropertyInfo propertyInfo) {
074: propertyInfos.add(propertyInfo);
075: fireTableRowsInserted(propertyInfos.size() - 1, propertyInfos
076: .size() - 1);
077: }
078:
079: private void removeProperty(int index) {
080: propertyInfos.remove(index);
081: fireTableRowsDeleted(index, index);
082: }
083:
084: public void removeProperties(@NotNull
085: int[] indices) {
086: for (int i = indices.length - 1; i >= 0; i--) {
087: int index = indices[i];
088: removeProperty(index);
089: }
090: }
091:
092: @Nullable
093: public String getColumnName(int column) {
094: if (column == 0) {
095: return TranslationManager.getInstance().getTranslation("R",
096: "PropertiesDataSetReportElement.Type.Title");
097: } else if (column == 1) {
098: return TranslationManager.getInstance().getTranslation("R",
099: "PropertiesDataSetReportElement.Value.Title");
100: }
101: return null;
102: }
103:
104: public void setValueAt(@Nullable
105: Object aValue, int rowIndex, int columnIndex) {
106: if (columnIndex == 1) {
107: propertyInfos.get(rowIndex).setValue(aValue);
108: }
109: }
110:
111: @Nullable
112: public Object getValueAt(int rowIndex, int columnIndex) {
113: if (columnIndex == 0) {
114: HashSet<Class<?>> hashSet = new HashSet<Class<?>>();
115: hashSet.add(propertyInfos.get(rowIndex).getClazz());
116: return hashSet;
117: } else if (columnIndex == 1) {
118: HashSet<Object> hashSet = new HashSet<Object>();
119: hashSet.add(propertyInfos.get(rowIndex).getValue());
120: return hashSet;
121: }
122: return null;
123: }
124: }
|