Source Code Cross Referenced for BookmarkFolderPropertyDialog.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » explorer » 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.explorer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.finix.contelligent.client.gui.explorer;
002:
003:        import java.awt.Dialog;
004:        import java.awt.event.ActionEvent;
005:        import java.util.ArrayList;
006:        import java.util.Enumeration;
007:        import java.util.Iterator;
008:
009:        import javax.swing.AbstractAction;
010:        import javax.swing.Action;
011:        import javax.swing.JButton;
012:        import javax.swing.JDialog;
013:        import javax.swing.JLabel;
014:        import javax.swing.JPanel;
015:        import javax.swing.JTextField;
016:        import javax.swing.JTree;
017:        import javax.swing.tree.DefaultMutableTreeNode;
018:        import javax.swing.tree.DefaultTreeModel;
019:
020:        import com.jgoodies.forms.extras.SimpleFormBuilder;
021:
022:        import de.finix.contelligent.client.i18n.Resources;
023:        import de.finix.contelligent.client.util.bookmark.Bookmark;
024:        import de.finix.contelligent.client.util.bookmark.BookmarkFolder;
025:        import de.finix.contelligent.client.util.bookmark.BookmarkManager;
026:
027:        public class BookmarkFolderPropertyDialog extends JDialog {
028:
029:            private BookmarkFolder bookmarkFolder = null;
030:
031:            private JTree bookmarksTree = null;
032:
033:            private JPanel panel = null;
034:
035:            private JLabel nameLabel = null;
036:
037:            private JTextField nameTextField = null;
038:
039:            private JPanel buttonPanel = null;
040:
041:            private JButton confirmButton = null;
042:
043:            private JButton closeButton = null;
044:
045:            /**
046:             * This is the default constructor
047:             */
048:            public BookmarkFolderPropertyDialog(Dialog owner,
049:                    BookmarkFolder bookmarkFolder, JTree bookmarksTree) {
050:                super (owner);
051:
052:                this .bookmarkFolder = bookmarkFolder;
053:                this .bookmarksTree = bookmarksTree;
054:
055:                initialize();
056:            }
057:
058:            /**
059:             * This method initializes this
060:             * 
061:             * @return void
062:             */
063:            private void initialize() {
064:
065:                panel = new JPanel();
066:
067:                // init layoutManager
068:                SimpleFormBuilder builder = new SimpleFormBuilder(
069:                        "related,labelColumn=pref,related,fieldColumn=pref:grow,related,related",
070:                        "related,nameRow=pref,related,buttonRow=pref,related");
071:                // Spalten und Zeilen
072:
073:                builder.add(getNameLabel(), "labelColumn,nameRow");
074:                builder.add(getNameTextField(), "fieldColumn,nameRow,2,1");
075:
076:                builder.add(getButtonPanel(), "fieldColumn,buttonRow,2,1");
077:
078:                panel = builder.getPanel();
079:                panel.setOpaque(false);
080:
081:                setContentPane(panel);
082:                setTitle(Resources.getLocalStringForPackage(
083:                        "bookmark_folder_property_editor_frame_title",
084:                        "languages.language"));
085:
086:                getRootPane().setDefaultButton(confirmButton);
087:
088:                setLocationByPlatform(true);
089:                setSize(500, 90);
090:                setResizable(false);
091:
092:                setModal(true);
093:            }
094:
095:            /**
096:             * @return the nameLabel
097:             */
098:            public JLabel getNameLabel() {
099:                if (nameLabel == null) {
100:                    nameLabel = new JLabel();
101:                    nameLabel.setText(Resources.getLocalStringForPackage(
102:                            "bookmark_name_frame_name_label",
103:                            "languages.language")
104:                            + ": ");
105:                }
106:                return nameLabel;
107:            }
108:
109:            /**
110:             * @return the nameTextField
111:             */
112:            private JTextField getNameTextField() {
113:                if (nameTextField == null) {
114:                    nameTextField = new JTextField();
115:                    nameTextField.setText(this .bookmarkFolder.getName());
116:
117:                    nameTextField.setEditable(true);
118:                    nameTextField.setEnabled(true);
119:                }
120:                return nameTextField;
121:            }
122:
123:            /**
124:             * @return
125:             */
126:            public JPanel getButtonPanel() {
127:                if (buttonPanel == null) {
128:                    buttonPanel = new JPanel();
129:
130:                    // init layoutManager
131:                    SimpleFormBuilder builder = new SimpleFormBuilder(
132:                            "related,confirmButtonColumn=pref,related,closeButtonColumn=pref,related",
133:                            "row=pref");
134:                    // Spalten und Zeilen
135:
136:                    builder.add(getConfirmButton(), "confirmButtonColumn,row");
137:                    builder.add(getCloseButton(), "closeButtonColumn,row");
138:
139:                    buttonPanel = builder.getPanel();
140:                    buttonPanel.setOpaque(false);
141:                }
142:                return buttonPanel;
143:            }
144:
145:            /**
146:             * @return the confirmButton
147:             */
148:            public JButton getConfirmButton() {
149:                if (confirmButton == null) {
150:                    confirmButton = new JButton(confirmAction);
151:
152:                    confirmButton.setText(Resources.getLocalStringForPackage(
153:                            "bookmark_name_frame_confirm_button",
154:                            "languages.language"));
155:                }
156:                return confirmButton;
157:            }
158:
159:            /**
160:             * @return the closeButton
161:             */
162:            public JButton getCloseButton() {
163:                if (closeButton == null) {
164:                    closeButton = new JButton(closeFrameAction);
165:
166:                    closeButton.setText(Resources.getLocalStringForPackage(
167:                            "bookmark_name_frame_close_button",
168:                            "languages.language"));
169:                }
170:                return closeButton;
171:            }
172:
173:            /**
174:             * 
175:             */
176:            Action confirmAction = new AbstractAction("confirmButton") {
177:                // This method is called when the button is pressed
178:                public void actionPerformed(ActionEvent evt) {
179:
180:                    // create new bookmarkFolder
181:                    String name = getNameTextField().getText().trim();
182:                    BookmarkFolder newBookmarkFolder = new BookmarkFolder(name);
183:
184:                    // replace bookmarkFolder = remove old and add new bookmarkFolder at the same node
185:                    BookmarkManager bookmarkManager = BookmarkManager
186:                            .getInstance();
187:                    bookmarkManager.replace(newBookmarkFolder, bookmarkFolder);
188:
189:                    // update tree visualization
190:                    // Because we know, that the model is of type DefaultTreeModel, we can explicit cast on it. 
191:                    DefaultTreeModel treeModel = (DefaultTreeModel) bookmarksTree
192:                            .getModel();
193:                    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) bookmarksTree
194:                            .getLastSelectedPathComponent();
195:
196:                    // get children of selected jtree node
197:                    ArrayList<DefaultMutableTreeNode> selectedNodeChildren = new ArrayList<DefaultMutableTreeNode>(
198:                            selectedNode.getChildCount());
199:
200:                    // save children of old node that will be deleted
201:                    for (Enumeration enumer = selectedNode.children(); enumer
202:                            .hasMoreElements();) {
203:                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) enumer
204:                                .nextElement();
205:                        selectedNodeChildren.add(element);
206:                    }
207:
208:                    // get parent of selected node
209:                    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode
210:                            .getParent();
211:
212:                    if (parent == null) {
213:                        // if parent is null, something went wrong.
214:                        // we close this dialog to enforce a revisualization of the tree.
215:                        dispose();
216:                    }
217:
218:                    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
219:                            name);
220:                    newNode.setUserObject(newBookmarkFolder);
221:
222:                    // remove old node
223:                    treeModel.removeNodeFromParent(selectedNode);
224:
225:                    int childCount = parent.getChildCount();
226:                    if (childCount > 0) {
227:
228:                        String compareName = null;
229:
230:                        // get count of bookmarkFolders to determine the position of the last folder in the tree.
231:                        int folderCount = 0;
232:                        for (int i = 0; i < childCount; i++) {
233:
234:                            DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent
235:                                    .getChildAt(i);
236:
237:                            if (node.getUserObject() instanceof  BookmarkFolder
238:                                    && !(node.getUserObject() instanceof  Bookmark)) {
239:                                folderCount++;
240:                            }
241:                        }
242:
243:                        if (folderCount == 0) {
244:                            // no other folders there, so just add at top
245:                            treeModel.insertNodeInto(newNode, parent, 0);
246:                        } else {
247:                            for (int i = 0; i < childCount; i++) {
248:                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent
249:                                        .getChildAt(i);
250:
251:                                if (node.getUserObject() instanceof  BookmarkFolder) {
252:
253:                                    if (node.getUserObject() instanceof  Bookmark) {
254:                                        // do nothing
255:                                    } else {
256:                                        BookmarkFolder bookmarkFolder = (BookmarkFolder) node
257:                                                .getUserObject();
258:                                        compareName = bookmarkFolder.getName();
259:
260:                                        if (newBookmarkFolder.getName()
261:                                                .compareTo(compareName) > 0) {
262:                                            // BookmarkFolder name is bigger than compareName
263:                                            if ((i + 1) == folderCount) {
264:                                                // add new node at the end of list
265:                                                treeModel.insertNodeInto(
266:                                                        newNode, parent, i + 1);
267:                                                break;
268:                                            }
269:                                        } else {
270:                                            // add new node
271:                                            treeModel.insertNodeInto(newNode,
272:                                                    parent, i);
273:                                            break;
274:                                        }
275:                                    }
276:                                }
277:                            }
278:                        }
279:                    } else {
280:                        // no children, then insert at index 0.
281:                        treeModel.insertNodeInto(newNode, parent, 0);
282:                        treeModel.reload();
283:                    }
284:
285:                    // move/add children of old node to new node
286:                    for (Iterator iter = selectedNodeChildren.iterator(); iter
287:                            .hasNext();) {
288:                        DefaultMutableTreeNode element = (DefaultMutableTreeNode) iter
289:                                .next();
290:                        newNode.add(element);
291:                    }
292:
293:                    dispose();
294:                }
295:            };
296:
297:            /**
298:             * 
299:             */
300:            Action closeFrameAction = new AbstractAction("closeButton") {
301:                // This method is called when the button is pressed
302:                public void actionPerformed(ActionEvent evt) {
303:
304:                    dispose();
305:                }
306:            };
307:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.