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:
042: package org.netbeans.modules.uml.integration.finddialog.ui;
043:
044: import java.util.Hashtable;
045: import javax.swing.Icon;
046: import javax.swing.event.TableModelListener;
047: import javax.swing.table.AbstractTableModel;
048: import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
049: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
050: import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
051: import org.netbeans.modules.uml.core.metamodel.structure.IProject;
052: import org.netbeans.modules.uml.core.support.umlutils.ETList;
053: import org.netbeans.modules.uml.ui.support.commonresources.CommonResourceManager;
054: import org.netbeans.modules.uml.integration.finddialog.FindUtilities;
055: import org.netbeans.modules.uml.ui.swing.preferencedialog.ISwingPreferenceTableModel;
056:
057: /**
058: * @author sumitabhk
059: *
060: */
061: public class FindTableModel extends AbstractTableModel implements
062: ISwingPreferenceTableModel {
063: private FindDialogUI m_FindControl = null;
064: private ReplaceDialogUI m_ReplaceControl = null;
065: private ETList<Object> m_collection = null;
066:
067: private Hashtable<Integer, String> m_ColNameMap = new Hashtable<Integer, String>();
068:
069: public FindTableModel() {
070: super ();
071: }
072:
073: public FindTableModel(FindDialogUI control) {
074: super ();
075: m_FindControl = control;
076: buildColumnMap();
077: }
078:
079: public FindTableModel(FindDialogUI control, ETList<Object> values) {
080: super ();
081: m_FindControl = control;
082: m_collection = values;
083: buildColumnMap();
084: }
085:
086: public FindTableModel(ReplaceDialogUI control) {
087: super ();
088: m_ReplaceControl = control;
089: buildColumnMap();
090: }
091:
092: public FindTableModel(ReplaceDialogUI control, ETList<Object> values) {
093: super ();
094: m_ReplaceControl = control;
095: m_collection = values;
096: buildColumnMap();
097: }
098:
099: /* (non-Javadoc)
100: * @see javax.swing.table.TableModel#getRowCount()
101: */
102: public int getRowCount() {
103: int retVal = 0;
104: if (m_collection != null) {
105: retVal = retVal + m_collection.size();
106: }
107: return retVal;
108: }
109:
110: /* (non-Javadoc)
111: * @see javax.swing.table.TableModel#getColumnCount()
112: */
113: public int getColumnCount() {
114: int count = 0;
115: ETList<String> strs = FindUtilities.buildColumns();
116: if (strs != null) {
117: count = strs.size();
118: }
119: return count;
120: }
121:
122: /* (non-Javadoc)
123: * @see javax.swing.table.TableModel#getColumnName(int)
124: */
125: public String getColumnName(int arg0) {
126: String dispColName = "";
127: Integer i = new Integer(arg0);
128: String colName = m_ColNameMap.get(i);
129: if (colName != null && colName.length() > 1) {
130: dispColName = FindUtilities.translateString(colName);
131: }
132: return dispColName;
133: }
134:
135: /* (non-Javadoc)
136: * @see javax.swing.table.TableModel#getColumnClass(int)
137: */
138: public Class getColumnClass(int arg0) {
139: if ("IDS_ICON".equals(m_ColNameMap.get(arg0)))
140: return Icon.class;
141: else
142: return String.class;
143: }
144:
145: /* (non-Javadoc)
146: * @see javax.swing.table.TableModel#isCellEditable(int, int)
147: */
148: public boolean isCellEditable(int arg0, int arg1) {
149: return false;
150: }
151:
152: /* (non-Javadoc)
153: * @see javax.swing.table.TableModel#getValueAt(int, int)
154: */
155: public Object getValueAt(int row, int col) {
156: Object retObj = null;
157: if (m_collection != null) {
158: int count = m_collection.size();
159: if (row <= count) {
160: for (int i = 0; i < count; i++) {
161: Object objVal = m_collection.get(i);
162: IElement pEle = null;
163: INamedElement namedEle = null;
164: IProxyDiagram pDiag = null;
165: if (objVal instanceof IElement) {
166: pEle = (IElement) objVal;
167: }
168: if (objVal instanceof INamedElement) {
169: namedEle = (INamedElement) objVal;
170: }
171: if (objVal instanceof IProxyDiagram) {
172: pDiag = (IProxyDiagram) objVal;
173: }
174: if (i == row) {
175: Integer theInt = new Integer(col);
176: String colName = m_ColNameMap.get(theInt);
177: //if (colName == null || colName.length() == 1)
178: if (colName.equals("IDS_ICON")) {
179: // not displaying the Icon title
180: CommonResourceManager mgr = CommonResourceManager
181: .instance();
182: retObj = mgr.getIconForDisp(objVal);
183: } else if (colName.equals("IDS_NAME")) {
184: if (namedEle != null) {
185: retObj = namedEle.getName();
186: } else if (pDiag != null) {
187: retObj = pDiag.getName();
188: }
189: } else if (colName.equals("IDS_ALIAS")) {
190: if (namedEle != null) {
191: retObj = namedEle.getAlias();
192: } else if (pDiag != null) {
193: retObj = pDiag.getAlias();
194: }
195: } else if (colName.equals("IDS_TYPE")) {
196: if (pEle != null) {
197: retObj = pEle.getExpandedElementType();
198: } else if (pDiag != null) {
199: retObj = pDiag.getDiagramKindName();
200: }
201: } else if (colName.equals("IDS_FULLNAME")) {
202: if (namedEle != null) {
203: retObj = namedEle.getQualifiedName2();
204: } else if (pDiag != null) {
205: retObj = pDiag.getQualifiedName();
206: }
207: } else if (colName.equals("IDS_PROJECT")) {
208: if (pEle != null) {
209: IProject pProj = pEle.getProject();
210: if (pProj != null) {
211: retObj = pProj.getName();
212: }
213: } else if (pDiag != null) {
214: IProject pProj = pDiag.getProject();
215: if (pProj != null) {
216: retObj = pProj.getName();
217: }
218: }
219: } else if (colName.equals("IDS_ID")) {
220: if (pEle != null) {
221: retObj = pEle.getXMIID();
222: } else if (pDiag != null) {
223: retObj = pDiag.getXMIID();
224: }
225: }
226: }
227: }
228: }
229: }
230: return retObj;
231: }
232:
233: /* (non-Javadoc)
234: * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
235: */
236: public void setValueAt(Object arg0, int arg1, int arg2) {
237: }
238:
239: /* (non-Javadoc)
240: * @see javax.swing.table.TableModel#addTableModelListener(javax.swing.event.TableModelListener)
241: */
242: public void addTableModelListener(TableModelListener arg0) {
243: }
244:
245: /* (non-Javadoc)
246: * @see javax.swing.table.TableModel#removeTableModelListener(javax.swing.event.TableModelListener)
247: */
248: public void removeTableModelListener(TableModelListener arg0) {
249: }
250:
251: public IElement getElementAtRow(int row) {
252: IElement retObj = null;
253: if (m_collection != null) {
254: int count = m_collection.size();
255: if (row <= count) {
256: for (int i = 0; i < count; i++) {
257: if (i == row) {
258: Object obj = m_collection.get(i);
259: if (obj instanceof IElement) {
260: retObj = (IElement) obj;
261: }
262: break;
263: }
264: }
265: }
266: }
267: return retObj;
268: }
269:
270: public IProxyDiagram getDiagramAtRow(int row) {
271: IProxyDiagram retObj = null;
272: if (m_collection != null) {
273: int count = m_collection.size();
274: if (row <= count) {
275: for (int i = 0; i < count; i++) {
276: if (i == row) {
277: Object obj = m_collection.get(i);
278: if (obj instanceof IProxyDiagram) {
279: retObj = (IProxyDiagram) obj;
280: }
281: break;
282: }
283: }
284: }
285: }
286: return retObj;
287: }
288:
289: private void buildColumnMap() {
290: ETList<String> strs = FindUtilities.buildColumns();
291: if (strs != null) {
292: int count = strs.size();
293: for (int x = 0; x < count; x++) {
294: String colName = strs.get(x);
295: if (colName != null && colName.length() > 1) {
296: Integer i = new Integer(x);
297: m_ColNameMap.put(i, colName);
298: }
299: }
300: }
301: }
302: }
|