KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > extenteditor > MappingCellEditor


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.modeler.extenteditor;
31
32 import java.awt.Component JavaDoc;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.event.ActionListener JavaDoc;
35 import java.awt.event.MouseEvent JavaDoc;
36 import java.util.EventObject JavaDoc;
37
38 import javax.swing.AbstractCellEditor JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JTable JavaDoc;
41 import javax.swing.table.TableCellEditor JavaDoc;
42
43 import com.genimen.djeneric.language.Messages;
44 import com.genimen.djeneric.repository.DjExtent;
45 import com.genimen.djeneric.repository.DjProperty;
46 import com.genimen.djeneric.ui.DjTable;
47 import com.genimen.djeneric.ui.Util;
48
49 public class MappingCellEditor extends AbstractCellEditor JavaDoc implements ActionListener JavaDoc, TableCellEditor JavaDoc
50 {
51   private static final long serialVersionUID = 1L;
52   protected JButton JavaDoc editorComponent;
53   protected int clickCountToStart = 2;
54
55   DjExtent _extent;
56   PropertyTableModel _model;
57
58   public MappingCellEditor(DjExtent table, PropertyTableModel model)
59   {
60     _extent = table;
61     _model = model;
62     editorComponent = new JButton JavaDoc();
63     editorComponent.addActionListener(this);
64   }
65
66   public Component JavaDoc getComponent()
67   {
68     return editorComponent;
69   }
70
71   public void setClickCountToStart(int count)
72   {
73     clickCountToStart = count;
74   }
75
76   public int getClickCountToStart()
77   {
78     return clickCountToStart;
79   }
80
81   public Object JavaDoc getCellEditorValue()
82   {
83     return _value;
84   }
85
86   Object JavaDoc _value = null;
87
88   public Component JavaDoc getTableCellEditorComponent(JTable JavaDoc table, Object JavaDoc value, boolean isSelected, int row, int column)
89   {
90     _value = value;
91     DjProperty col = _extent.getProperty(row);
92
93     MappingChooser chooser = new MappingChooser(Util.findFrame(table), Messages
94         .getString("MappingCellEditor.SelectMapping"), value.toString(), _extent, col.getName());
95     if (!chooser.isCancelled())
96     {
97       if (chooser.getMapping() == null) return null;
98       _model.setValueAt(chooser.getMapping(), row, column);
99       if (table instanceof DjTable)
100       {
101         ((DjTable) table).nextCell();
102       }
103     }
104     return null;
105   }
106
107   public boolean shouldSelectCell(EventObject JavaDoc anEvent)
108   {
109     return true;
110   }
111
112   public boolean startCellEditing(EventObject JavaDoc anEvent)
113   {
114     return true;
115   }
116
117   public boolean stopCellEditing()
118   {
119     fireEditingStopped();
120     return true;
121   }
122
123   public void cancelCellEditing()
124   {
125     fireEditingCanceled();
126   }
127
128   public void actionPerformed(ActionEvent JavaDoc e)
129   {
130     stopCellEditing();
131   }
132
133   public boolean isCellEditable(EventObject JavaDoc anEvent)
134   {
135     if (anEvent instanceof MouseEvent JavaDoc)
136     {
137       return ((MouseEvent JavaDoc) anEvent).getClickCount() >= clickCountToStart;
138     }
139     return true;
140   }
141 }
Popular Tags