001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.sql.framework.ui.view.graph;
042:
043: import java.util.Vector;
044:
045: import javax.swing.AbstractListModel;
046:
047: import com.sun.sql.framework.exception.BaseException;
048: import net.java.hulp.i18n.Logger;
049: import org.netbeans.modules.etl.logger.Localizer;
050: import org.netbeans.modules.etl.logger.LogUtil;
051:
052: /**
053: * This class represents model for SQLCaseArea
054: *
055: * @author Ritesh Adval
056: */
057: public class CaseListModel extends AbstractListModel {
058:
059: private Vector listItems = new Vector();
060: private static transient final Logger mLogger = LogUtil
061: .getLogger(CaseListModel.class.getName());
062: private static transient final Localizer mLoc = Localizer.get();
063:
064: /** Creates a new instance of CaseListModel */
065: public CaseListModel() {
066: }
067:
068: /**
069: * Returns the value at the specified index.
070: *
071: * @param index the requested index
072: * @return the value at <code>index</code>
073: */
074: public Object getElementAt(int index) {
075: if (index < listItems.size()) {
076: return listItems.get(index);
077: }
078:
079: return null;
080: }
081:
082: /**
083: * Returns the length of the list.
084: *
085: * @return the length of the list
086: */
087: public int getSize() {
088: return listItems.size();
089: }
090:
091: /**
092: * always add element not at the end but before last element
093: *
094: * @param val value to add
095: */
096: public void add(Object val) {
097: if (!listItems.contains(val)) {
098: listItems.add(val);
099: int idx = listItems.indexOf(val);
100: fireIntervalAdded(this , idx, idx);
101: }
102: }
103:
104: /**
105: * add element at the specified index
106: *
107: * @param row row index
108: * @param val object value
109: */
110: public void add(int row, Object val) {
111: listItems.add(row, val);
112: fireIntervalAdded(this , row, row);
113: }
114:
115: /**
116: * get index of an object
117: *
118: * @param val object whose index needs to be found
119: * @param return index of object
120: */
121: public int indexOf(Object val) {
122: return listItems.indexOf(val);
123: }
124:
125: /**
126: * remove an object for the model
127: *
128: * @param val object to be removed
129: */
130: public boolean remove(Object val) throws BaseException {
131: if (listItems.size() == 1) {
132: return false;
133: }
134:
135: if (!listItems.contains(val)) {
136: String nbBundle1 = mLoc
137: .t("PRSR001: Cannot remove selected when condition.");
138: throw new BaseException(Localizer.parse(nbBundle1));
139: }
140:
141: int idx = listItems.indexOf(val);
142: listItems.remove(idx);
143: fireIntervalRemoved(this , idx, idx);
144:
145: return true;
146: }
147: }
|