Source Code Cross Referenced for TableEditor.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » composed » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » contelligent » de.finix.contelligent.client.gui.composed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.gui.composed;
019:
020:        import java.awt.BorderLayout;
021:        import java.awt.Toolkit;
022:        import java.awt.datatransfer.Clipboard;
023:        import java.awt.datatransfer.ClipboardOwner;
024:        import java.awt.datatransfer.Transferable;
025:        import java.awt.datatransfer.UnsupportedFlavorException;
026:        import java.awt.event.ActionEvent;
027:        import java.awt.event.FocusAdapter;
028:        import java.awt.event.FocusEvent;
029:        import java.io.IOException;
030:        import java.util.logging.Level;
031:        import java.util.logging.Logger;
032:
033:        import javax.swing.AbstractAction;
034:        import javax.swing.Action;
035:        import javax.swing.JOptionPane;
036:        import javax.swing.JScrollPane;
037:        import javax.swing.ListSelectionModel;
038:
039:        import de.finix.contelligent.client.base.ComponentFactory;
040:        import de.finix.contelligent.client.base.ComponentNotFoundException;
041:        import de.finix.contelligent.client.base.ContelligentComponent;
042:        import de.finix.contelligent.client.base.Type;
043:        import de.finix.contelligent.client.event.ContelligentEvent;
044:        import de.finix.contelligent.client.gui.AbstractComponentEditor;
045:        import de.finix.contelligent.client.gui.ContelligentAction;
046:        import de.finix.contelligent.client.gui.text.StringOptionPane;
047:        import de.finix.contelligent.client.i18n.Resources;
048:        import de.finix.contelligent.client.remote.ActionResult;
049:        import de.finix.contelligent.client.remote.Actions;
050:        import de.finix.contelligent.client.remote.RemoteActionException;
051:        import de.finix.contelligent.client.util.ComponentMovement;
052:        import de.finix.contelligent.client.util.ExceptionDialog;
053:        import de.finix.contelligent.client.util.dnd.SingleComponentTransferable;
054:
055:        public class TableEditor extends AbstractComponentEditor implements 
056:                ClipboardOwner {
057:
058:            private final static int TABLE_DM_COMPONENT_COLUMN = 0;
059:
060:            private static Logger logger = Logger.getLogger(TableEditor.class
061:                    .getName());
062:
063:            private ComponentTableModel componentTableModel;
064:
065:            private ComponentTable componentTable;
066:
067:            private JScrollPane scrollPane;
068:
069:            private AddRowAction addRowAction = new AddRowAction();
070:
071:            private DeleteRowAction deleteRowAction = new DeleteRowAction();
072:
073:            private CopyRowAction copyRowAction = new CopyRowAction();
074:
075:            private PasteRowAction pasteRowAction = new PasteRowAction();
076:
077:            private MoveUpAction moveUpAction = new MoveUpAction();
078:
079:            private MoveDownAction moveDownAction = new MoveDownAction();
080:
081:            public void init() {
082:
083:                update();
084:                scrollPane = new JScrollPane(componentTable);
085:                scrollPane.getViewport().setOpaque(false);
086:                scrollPane.setOpaque(false);
087:                add(scrollPane, BorderLayout.CENTER);
088:
089:                componentTable.getSelectionModel().setSelectionMode(
090:                        ListSelectionModel.SINGLE_SELECTION);
091:
092:                componentTable.addFocusListener(new FocusAdapter() {
093:                    public void focusGained(FocusEvent e) {
094:                        getView().setActions(getActions());
095:                    }
096:                });
097:            }
098:
099:            public void invalidate() {
100:                super .invalidate();
101:            }
102:
103:            public void update() {
104:
105:                if (componentTableModel == null) {
106:                    componentTableModel = new ComponentTableModel(
107:                            getComponent(), getView(),
108:                            ComponentTableModel.TABLE);
109:                    componentTableModel.setEditable(isEditable());
110:                    componentTable = new ComponentTable(componentTableModel,
111:                            getView());
112:                } else {
113:                    componentTableModel.updateModel();
114:                    componentTable.calculateColumnWidths();
115:                    componentTable.calculateRowHeights();
116:                }
117:
118:                enableActions();
119:            }
120:
121:            private void enableActions() {
122:                if (getComponent().getType().getName().equals(
123:                        Type.SORTED_FOLDER)) {
124:                    int index = componentTable.getSelectedRow();
125:
126:                    if (index == -1) {
127:                        deleteRowAction.setEnabled(false);
128:                        copyRowAction.setEnabled(false);
129:                        moveUpAction.setEnabled(false);
130:                        moveDownAction.setEnabled(false);
131:                    } else if (index == 0) {
132:                        moveUpAction.setEnabled(false);
133:                    } else if (index == componentTableModel.getRowCount() - 1) {
134:                        moveDownAction.setEnabled(false);
135:                    }
136:
137:                    deleteRowAction.setEnabled(true);
138:                    copyRowAction.setEnabled(true);
139:
140:                } else {
141:                    moveDownAction.setEnabled(false);
142:                    moveUpAction.setEnabled(false);
143:                }
144:            }
145:
146:            public void setEditable(boolean editable) {
147:                super .setEditable(editable);
148:                if (componentTableModel != null) {
149:                    componentTableModel.setEditable(isEditable());
150:                }
151:            }
152:
153:            public void rollback() {
154:                componentTableModel.rollback();
155:                setEditable(false);
156:            }
157:
158:            public void commit() {
159:                componentTableModel.commit();
160:                setEditable(false);
161:            }
162:
163:            public Action[] getActions() {
164:                if (isEditable()) {
165:                    return new Action[] { deleteRowAction, copyRowAction,
166:                            pasteRowAction, moveUpAction, moveDownAction };
167:                } else {
168:                    return new Action[0];
169:                }
170:            }
171:
172:            protected void updateComponent() {
173:            }
174:
175:            protected void componentChanged(ContelligentEvent event) {
176:                update();
177:            }
178:
179:            protected void childComponentAdded(ContelligentEvent event) {
180:            }
181:
182:            protected void childComponentRemoved(ContelligentEvent event) {
183:            }
184:
185:            protected void childComponentChanged(ContelligentEvent event) {
186:            }
187:
188:            protected void descendentComponentChanged(ContelligentEvent event) {
189:            }
190:
191:            public class AddRowAction extends AbstractAction implements 
192:                    ContelligentAction {
193:
194:                public AddRowAction() {
195:                    super ("add_row", Resources.newIcon);
196:                    putValue(ROLLOVER_ICON, Resources.newIconRollOver);
197:                    putValue(TYPE, PUSH_ACTION);
198:                    putValue(ACTION_TYPE, EDIT_ACTION);
199:                    putValue(MENU_TARGET, MENU);
200:                    putValue(BUTTON_TARGET, TOOLBAR);
201:                }
202:
203:                public void actionPerformed(ActionEvent e) {
204:                    try {
205:                        // ask for the name of the new component
206:                        StringOptionPane stringOptionPane = new StringOptionPane();
207:                        if (stringOptionPane.showStringDialog(Resources
208:                                .getLocalString("component_name"), Resources
209:                                .getLocalString("new_component_name")
210:                                + ":", "new" + getComponent().getName()) == StringOptionPane.OK_OPTION) {
211:                            String name = stringOptionPane.getText();
212:                            if (name.length() > 0) {
213:                                // FIXME doesnt work!!!:
214:                                ActionResult result = Actions.create(getView()
215:                                        .getEnvironment(), getComponent()
216:                                        .getPath(), name, name);
217:                                result.showErrors();
218:                            }
219:                        }
220:                    } catch (RemoteActionException rae) {
221:                        ExceptionDialog.show(rae);
222:                    }
223:                }
224:            }
225:
226:            public class DeleteRowAction extends AbstractAction implements 
227:                    ContelligentAction {
228:
229:                public DeleteRowAction() {
230:                    super ("delete_row", Resources.deleteIcon);
231:                    putValue(ROLLOVER_ICON, Resources.deleteIconRollOver);
232:                    putValue(TYPE, PUSH_ACTION);
233:                    putValue(ACTION_TYPE, EDIT_ACTION);
234:                    putValue(MENU_TARGET, MENU);
235:                    putValue(BUTTON_TARGET, TOOLBAR);
236:                }
237:
238:                public void actionPerformed(ActionEvent e) {
239:                    int index = componentTable.getSelectedRow();
240:                    if (index != -1) {
241:                        try {
242:                            int answer = JOptionPane
243:                                    .showConfirmDialog(
244:                                            null,
245:                                            Resources
246:                                                    .getLocalString("delete_selected_row_question"),
247:                                            Resources
248:                                                    .getLocalString("comfirm_delete"),
249:                                            JOptionPane.YES_NO_OPTION);
250:                            if (answer == JOptionPane.YES_OPTION) {
251:                                String name = (String) componentTable
252:                                        .getValueAt(index, 0);
253:                                ActionResult result = Actions.delete(getView()
254:                                        .getEnvironment(), getComponent()
255:                                        .getPath()
256:                                        + "/" + name, false);
257:                                result.showErrors();
258:                            }
259:                        } catch (RemoteActionException rae) {
260:                            ExceptionDialog.show(rae);
261:                        }
262:                    }
263:                }
264:            }
265:
266:            public class CopyRowAction extends AbstractAction implements 
267:                    ContelligentAction {
268:
269:                public CopyRowAction() {
270:                    super ("copy_row", Resources.copyIcon);
271:                    putValue(ROLLOVER_ICON, Resources.copyIconRollOver);
272:                    putValue(TYPE, PUSH_ACTION);
273:                    putValue(ACTION_TYPE, EDIT_ACTION);
274:                    putValue(MENU_TARGET, MENU);
275:                    putValue(BUTTON_TARGET, TOOLBAR);
276:                }
277:
278:                public void actionPerformed(ActionEvent e) {
279:                    // copy component to clipboard
280:                    ContelligentComponent component = (ContelligentComponent) componentTable
281:                            .getValueAt(componentTable.getSelectedRow(), 1);
282:                    Clipboard clipboard = Toolkit.getDefaultToolkit()
283:                            .getSystemClipboard();
284:                    clipboard.setContents(new SingleComponentTransferable(
285:                            component, getView().getEnvironment()),
286:                            (ClipboardOwner) this );
287:                }
288:            }
289:
290:            public class PasteRowAction extends AbstractAction implements 
291:                    ContelligentAction {
292:
293:                public PasteRowAction() {
294:                    super ("paste_row", Resources.pasteIcon);
295:                    putValue(ROLLOVER_ICON, Resources.pasteIconRollOver);
296:                    putValue(TYPE, PUSH_ACTION);
297:                    putValue(ACTION_TYPE, EDIT_ACTION);
298:                    putValue(MENU_TARGET, MENU);
299:                    putValue(BUTTON_TARGET, TOOLBAR);
300:                }
301:
302:                public void actionPerformed(ActionEvent e) {
303:                    Clipboard clipboard = Toolkit.getDefaultToolkit()
304:                            .getSystemClipboard();
305:                    Transferable clipData = clipboard.getContents(clipboard);
306:                    if (clipData != null) {
307:                        // ask for the name of the new component
308:                        StringOptionPane stringOptionPane = new StringOptionPane();
309:                        if (stringOptionPane.showStringDialog(Resources
310:                                .getLocalString("component_name"), Resources
311:                                .getLocalString("new_component_name")
312:                                + ":", "new"
313:                                + TableEditor.this .getComponent().getName()) == StringOptionPane.OK_OPTION) {
314:                            String name = stringOptionPane.getText();
315:                            if (name.length() > 0) {
316:                                try {
317:                                    ContelligentComponent pastedComponent = (ContelligentComponent) clipData
318:                                            .getTransferData(SingleComponentTransferable.componentFlavor);
319:                                    String sourceEnvironment = (String) clipData
320:                                            .getTransferData(SingleComponentTransferable.sourceEnvironmentFlavor);
321:                                    ComponentMovement.nonBlockingCopy(getView()
322:                                            .getEnvironment(),
323:                                            sourceEnvironment, pastedComponent,
324:                                            getComponent(), name, false, false);
325:                                } catch (UnsupportedFlavorException ee) {
326:                                    ExceptionDialog.show(ee);
327:                                } catch (IOException ioe) {
328:                                    ExceptionDialog.show(ioe);
329:                                }
330:                            }
331:                        }
332:                    }
333:                }
334:            }
335:
336:            public class MoveUpAction extends AbstractAction implements 
337:                    ContelligentAction {
338:
339:                public MoveUpAction() {
340:                    super ("move_up_row", Resources.moveUpIcon);
341:                    putValue(ROLLOVER_ICON, Resources.moveUpIconRollOver);
342:                    putValue(TYPE, PUSH_ACTION);
343:                    putValue(ACTION_TYPE, EDIT_ACTION);
344:                    putValue(MENU_TARGET, MENU);
345:                    putValue(BUTTON_TARGET, TOOLBAR);
346:                }
347:
348:                public void actionPerformed(ActionEvent e) {
349:                    int index = componentTable.getSelectedRow();
350:                    try {
351:                        ContelligentComponent moveComponent = (ContelligentComponent) componentTable
352:                                .getValueAt(index, TABLE_DM_COMPONENT_COLUMN);
353:                        ActionResult result = Actions.sort(getView()
354:                                .getEnvironment(), moveComponent.getPath(),
355:                                Actions.UP);
356:                        result.showErrors();
357:                    } catch (RemoteActionException rae) {
358:                        ExceptionDialog.show(rae);
359:                    }
360:                }
361:            }
362:
363:            public class MoveDownAction extends AbstractAction implements 
364:                    ContelligentAction {
365:
366:                public MoveDownAction() {
367:                    super ("move_down_row", Resources.moveDownIcon);
368:                    putValue(ROLLOVER_ICON, Resources.moveDownIconRollOver);
369:                    putValue(TYPE, PUSH_ACTION);
370:                    putValue(ACTION_TYPE, EDIT_ACTION);
371:                    putValue(MENU_TARGET, MENU);
372:                    putValue(BUTTON_TARGET, TOOLBAR);
373:                }
374:
375:                public void actionPerformed(ActionEvent e) {
376:                    int index = componentTable.getSelectedRow();
377:                    String name = (String) componentTable.getValueAt(index, 0);
378:                    try {
379:                        ContelligentComponent moveComponent = ComponentFactory
380:                                .getInstance().getComponent(
381:                                        getComponent().getPath() + "/" + name);
382:                        ActionResult result = Actions.sort(getView()
383:                                .getEnvironment(), moveComponent.getPath(),
384:                                Actions.DOWN);
385:                        result.showErrors();
386:                    } catch (RemoteActionException rae) {
387:                        ExceptionDialog.show(rae);
388:                    } catch (ComponentNotFoundException cnfe) {
389:                        ExceptionDialog.show(cnfe);
390:                    }
391:                }
392:            }
393:
394:            public void lostOwnership(Clipboard clipboard,
395:                    Transferable transferable) {
396:                logger.log(Level.FINE, "lost ownership");
397:            }
398:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.