001: package com.xoetrope.carousel.visualizer;
002:
003: import com.xoetrope.data.pojo.XPojoIteratorEx;
004: import com.xoetrope.data.pojo.XPojoMethodArg;
005: import com.xoetrope.data.pojo.XPojoMethodArgs;
006: import com.xoetrope.data.pojo.XPojoModelEx;
007: import java.awt.Component;
008: import javax.swing.ImageIcon;
009: import javax.swing.JPanel;
010: import net.xoetrope.optional.data.sql.DatabaseFieldModel;
011: import net.xoetrope.optional.data.sql.DatabaseRowModel;
012: import net.xoetrope.optional.data.sql.DatabaseTableModel;
013: import net.xoetrope.xui.XProject;
014: import net.xoetrope.xui.XProjectManager;
015: import net.xoetrope.xui.data.XModel;
016:
017: public class XModelVisualizerFactory {
018: private static String iconPath = "com/xoetrope/carousel/resources/icons/visualiser/";
019:
020: private static ImageIcon loadingIcon;
021:
022: private static ImageIcon staticTableIcon;
023: private static ImageIcon dataItemIcon;
024: private static ImageIcon dataListIcon;
025: private static ImageIcon dbTableIcon;
026:
027: private static ImageIcon dataSetIcon;
028: private static ImageIcon dataSetsIcon;
029:
030: private static ImageIcon pojPropertyIcon;
031: private static ImageIcon pojTransientPropertyIcon;
032: private static ImageIcon pojCollectionIcon;
033: private static ImageIcon pojIteratorIcon;
034: private static ImageIcon pojMethodArgumentIcon;
035: private static ImageIcon pojMethodArgumentsIcon;
036:
037: /**
038: * Determines whether the <code>model</code> is database table
039: * model node.
040: * @param model the XModel that is being checked
041: * @return <code>true</code> if the model is DatabaseTableModel or
042: * runtime wrapper for DatabaseTableModel, <code>false</code> otherwise
043: */
044: public static boolean isDbTableModel(XModel model) {
045: boolean status = false;
046: if (model instanceof VisualiserDebuggerModel) {
047: String rns = ((VisualiserDebuggerModel) model)
048: .getNodeString();
049: status = ((rns != null) && (rns
050: .indexOf("DatabaseTableModel") != -1));
051: } else {
052: status = (model instanceof DatabaseTableModel);
053: }
054: return status;
055: }
056:
057: /**
058: * Determines whether the <code>model</code> is database row
059: * model node.
060: * @param model the XModel that is being checked
061: * @return <code>true</code> if the model is DatabaseRowModel or
062: * runtime wrapper for DatabaseRowModel, <code>false</code> otherwise
063: */
064: public static boolean isDbRowModel(XModel model) {
065: boolean status = false;
066: if (model instanceof VisualiserDebuggerModel) {
067: String rns = ((VisualiserDebuggerModel) model)
068: .getNodeString();
069: status = (rns.indexOf("DatabaseRowModel") != -1);
070: } else {
071: status = (model instanceof DatabaseRowModel);
072: }
073: return status;
074: }
075:
076: /**
077: * Determines whether the <code>model</code> is database row
078: * model node.
079: * @param model the XModel that is being checked
080: * @return <code>true</code> if the model is DatabaseFieldModel or
081: * runtime wrapper for DatabaseFieldModel, <code>false</code> otherwise
082: */
083: public static boolean isDbFieldModel(XModel model) {
084: boolean status = false;
085: if (model instanceof VisualiserDebuggerModel) {
086: String rns = ((VisualiserDebuggerModel) model)
087: .getNodeString();
088: status = (rns.indexOf("DatabaseFieldModel") != -1);
089: } else {
090: status = (model instanceof DatabaseFieldModel);
091: }
092:
093: /* for node representing database field model "getRootNodeString" method
094: * may not return String containing "DatabaseFieldModel" so check if
095: * parent node is database row model. */
096: if ((!status) && (model != null) && (model.getParent() != null))
097: status = isDbRowModel(model.getParent());
098: return status;
099: }
100:
101: /**
102: * Determines whether <code>model</code> is static table
103: * model node
104: * @param model the XModel node to be checked
105: * @return true if the model is a static table model node,
106: * false otherwise
107: */
108: public static boolean isStaticTableModel(XModel model) {
109: return ((model != null) && "table".equals(model.getTagName()));
110: }
111:
112: public static boolean isStaticListModel(XModel model) {
113: return ((model != null) && "list".equals(model.getTagName()));
114: }
115:
116: /**
117: * Determines whether <code>model</code> is POJO model node.
118: * @param model the XModel node to be checked
119: * @return true if the model is a POJO model node,
120: * false otherwise
121: */
122: public static boolean isPojoModel(XModel model) {
123: return (model instanceof XPojoModelEx);
124: }
125:
126: /**
127: * Indicates whether the specified model node
128: * is wrapping a collection object (as the pojo property)
129: */
130: public static boolean isPojoCollectionProperty(XModel model) {
131: if (!(model instanceof XPojoModelEx))
132: return false;
133: return ((XPojoModelEx) model).isCollection();
134: }
135:
136: /**
137: * Gets whehter the specified model node represents
138: * a pojo property.
139: */
140: public static boolean isPojoProperty(XModel model) {
141: if (!(model instanceof XPojoModelEx))
142: return false;
143: XPojoModelEx pojoModel = (XPojoModelEx) model;
144: return (!pojoModel.isCollection() && !pojoModel.isTransient());
145: }
146:
147: /**
148: * Gets whether the specified model node represents
149: * a transient pojo property.
150: */
151: public static boolean isPojoTransientProperty(XModel model) {
152: if (!(model instanceof XPojoModelEx))
153: return false;
154: XPojoModelEx pojoModel = (XPojoModelEx) model;
155: return (!pojoModel.isCollection() && pojoModel.isTransient());
156: }
157:
158: /**
159: * Gets whether the specified model node represents
160: * a pojo iterator.
161: */
162: public static boolean isPojoIterator(XModel model) {
163: return (model instanceof XPojoIteratorEx);
164: }
165:
166: public static boolean isLoading(XModel model) {
167: return (model == null);
168: }
169:
170: /**
171: * Gets whether the specified model node represents
172: * one single argument of the pojo method.
173: */
174: public static boolean isPojoMethodArgument(XModel model) {
175: return (model instanceof XPojoMethodArg);
176: }
177:
178: /**
179: * Gets whether the specified model node represents
180: * arguments of the pojo method.
181: */
182: public static boolean isPojoMethodArguments(XModel model) {
183: return (model instanceof XPojoMethodArgs);
184: }
185:
186: /**
187: * Gets the data visualiser icon representation of the node "getting value.."
188: */
189: public static ImageIcon getLoadingIcon() {
190: if (loadingIcon == null) {
191: XProject currentProject = XProjectManager
192: .getCurrentProject();
193: loadingIcon = new ImageIcon(currentProject
194: .getImage(iconPath + "loading.png"));
195: }
196: return loadingIcon;
197: }
198:
199: /**
200: * Gets the data visualiser icon representation of the pojo property.
201: */
202: public static ImageIcon getPojoPropertyIcon() {
203: if (pojPropertyIcon == null) {
204: XProject currentProject = XProjectManager
205: .getCurrentProject();
206: pojPropertyIcon = new ImageIcon(currentProject
207: .getImage(iconPath + "pojo.png"));
208: }
209: return pojPropertyIcon;
210: }
211:
212: /**
213: * Gets the data visualiser icon representation
214: * of the pojo transient property
215: */
216: public static ImageIcon getPojTransientPropertyIcon() {
217: if (pojTransientPropertyIcon == null) {
218: XProject currentProject = XProjectManager
219: .getCurrentProject();
220: pojTransientPropertyIcon = new ImageIcon(currentProject
221: .getImage(iconPath + "pojo_transient.png"));
222: }
223: return pojTransientPropertyIcon;
224: }
225:
226: /**
227: * Gets the data visualiser icon representation of
228: * the pojo collection property
229: */
230: public static ImageIcon getPojCollectionIcon() {
231: if (pojCollectionIcon == null) {
232: XProject currentProject = XProjectManager
233: .getCurrentProject();
234: pojCollectionIcon = new ImageIcon(currentProject
235: .getImage(iconPath + "collection.png"));
236: }
237: return pojCollectionIcon;
238: }
239:
240: /**
241: * Gets the data visualiser icon representation of
242: * the pojo collection iterator.
243: */
244: public static ImageIcon getPojIteratorIcon() {
245: if (pojIteratorIcon == null) {
246: XProject currentProject = XProjectManager
247: .getCurrentProject();
248: pojIteratorIcon = new ImageIcon(currentProject
249: .getImage(iconPath + "pojo_iterator.png"));
250: }
251: return pojIteratorIcon;
252: }
253:
254: /**
255: * Gets the data visualiser icon representation of
256: * the signel argument of the pojo method.
257: */
258: public static ImageIcon getPojMethodArgumentIcon() {
259: if (pojMethodArgumentIcon == null) {
260: XProject currentProject = XProjectManager
261: .getCurrentProject();
262: pojMethodArgumentIcon = new ImageIcon(currentProject
263: .getImage(iconPath + "pojArgument.png"));
264: }
265: return pojMethodArgumentIcon;
266: }
267:
268: /**
269: * Gets the data visualiser icon representation of
270: * the arguments of the pojo method.
271: */
272: public static ImageIcon getPojMethodArgumentsIcon() {
273: if (pojMethodArgumentsIcon == null) {
274: XProject currentProject = XProjectManager
275: .getCurrentProject();
276: pojMethodArgumentsIcon = new ImageIcon(currentProject
277: .getImage(iconPath + "pojArgumentPreview.png"));
278: }
279: return pojMethodArgumentsIcon;
280: }
281:
282: /**
283: * Returns the icon representing the table
284: */
285: private static ImageIcon getStaticTableIcon() {
286: if (staticTableIcon == null) {
287: XProject currentProject = XProjectManager
288: .getCurrentProject();
289: staticTableIcon = new ImageIcon(currentProject
290: .getImage(iconPath + "table.png"));
291: }
292: return staticTableIcon;
293: }
294:
295: private static ImageIcon getDbTableIcon() {
296: if (dbTableIcon == null) {
297: XProject currentProject = XProjectManager
298: .getCurrentProject();
299: dbTableIcon = new ImageIcon(currentProject
300: .getImage(iconPath + "dbtableicon.png"));
301: }
302: return dbTableIcon;
303: }
304:
305: private static ImageIcon getDataItemIcon() {
306: if (dataItemIcon == null) {
307: XProject currentProject = XProjectManager
308: .getCurrentProject();
309: dataItemIcon = new ImageIcon(currentProject
310: .getImage(iconPath + "dataitemicon.gif"));
311: }
312: return dataItemIcon;
313: }
314:
315: private static ImageIcon getDataListIcon() {
316: if (dataListIcon == null) {
317: XProject currentProject = XProjectManager
318: .getCurrentProject();
319: dataListIcon = new ImageIcon(currentProject
320: .getImage(iconPath + "datalisticon.gif"));
321: }
322: return dataListIcon;
323: }
324:
325: private static ImageIcon getDataSetIcon() {
326: if (dataSetIcon == null) {
327: XProject currentProject = XProjectManager
328: .getCurrentProject();
329: dataSetIcon = new ImageIcon(currentProject
330: .getImage(iconPath + "seticon.gif"));
331: }
332: return dataSetIcon;
333: }
334:
335: private static ImageIcon getDataSetsIcon() {
336: if (dataSetsIcon == null) {
337: XProject currentProject = XProjectManager
338: .getCurrentProject();
339: dataSetsIcon = new ImageIcon(currentProject
340: .getImage(iconPath + "datasetsicon.gif"));
341: }
342: return dataSetsIcon;
343: }
344:
345: /**
346: * Returns the visualizer for the model node
347: * @param node the XModel node
348: * @param panel panel that will contain returned component.
349: * @return the Component visualizer for the model node.
350: * or a plain <code>JPanel</code> if the <code>node</code>'s type is
351: * not known.
352: */
353: public static Component getVisualizer(XModel node,
354: ModelVisualiserPanel panel) {
355: Component comp = new JPanel();
356: if (isStaticTableModel(node))
357: comp = new XTableModelPanel(node, panel);
358: else if (isDbTableModel(node))
359: comp = new XTableModelPanel(node, panel);
360: else if (isPojoMethodArguments(node))
361: comp = new XPojoArgsModelView((XPojoMethodArgs) node, panel);
362: return comp;
363: }
364:
365: /**
366: * Gets the icon for the given model node type.
367: * @param model the model node whose icon representation
368: * is to be returned
369: * @return ImageIcon object
370: */
371: public static ImageIcon getIcon(XModel model) {
372: ImageIcon icon = null;
373:
374: if (isLoading(model))
375: icon = getLoadingIcon();
376: else if (isPojoIterator(model))
377: icon = getPojIteratorIcon();
378: else if (isPojoTransientProperty(model))
379: icon = getPojTransientPropertyIcon();
380: else if (isPojoProperty(model))
381: icon = getPojoPropertyIcon();
382: else if (isPojoCollectionProperty(model))
383: icon = getPojCollectionIcon();
384: else if (isPojoMethodArgument(model))
385: icon = getPojMethodArgumentIcon();
386: else if (isPojoMethodArguments(model))
387: icon = getPojMethodArgumentsIcon();
388: else if (isDbTableModel(model))
389: icon = getDbTableIcon();
390: else if (isStaticTableModel(model))
391: icon = getStaticTableIcon();
392: else if (isStaticListModel(model))
393: icon = getDataListIcon();
394:
395: return icon;
396: }
397:
398: /**
399: * Returns the icon for the visualiser
400: * @param dataName the path of the model node
401: * @return visualizer icon
402: */
403: public static ImageIcon getIcon(String dataName) {
404: ImageIcon icon = null;
405: if (dataName.equals("")) {
406: icon = getDataItemIcon();
407: } else {
408: XProject currentProject = XProjectManager
409: .getCurrentProject();
410: XModel model = (XModel) currentProject.getModel().get(
411: dataName);
412: String tag = model.getTagName();
413: if (tag.equals("table"))
414: icon = getStaticTableIcon();
415: }
416: return icon;
417: }
418:
419: }
|