Source Code Cross Referenced for FilteredItemManager.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » products » ad » projecttreedefaultengine » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.ui.products.ad.projecttreedefaultengine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        /*
043:         *
044:         * Created on Jun 12, 2003
045:         * @author Trey Spiva
046:         */
047:        package org.netbeans.modules.uml.ui.products.ad.projecttreedefaultengine;
048:
049:        import java.util.HashMap;
050:        import java.util.Iterator;
051:        import java.util.Set;
052:        import java.util.TreeMap;
053:
054:        import org.netbeans.modules.uml.core.support.umlsupport.IResultCell;
055:        import org.netbeans.modules.uml.ui.controls.filter.FilterItem;
056:        import org.netbeans.modules.uml.ui.controls.filter.IFilterDialog;
057:        import org.netbeans.modules.uml.ui.controls.filter.IFilterItem;
058:        import org.netbeans.modules.uml.ui.controls.filter.IFilterNode;
059:        import org.netbeans.modules.uml.ui.controls.filter.ProjectTreeFilterDialogEventsAdapter;
060:        import org.netbeans.modules.uml.ui.support.UserSettings;
061:
062:        /**
063:         * Manages the project tree filter items.  Uses the
064:         * IProjectTreeFilterDialogEventsSink interface to add items to the filter
065:         * dialog.
066:         * 
067:         * @author Trey Spiva
068:         * @see IProjectTreeFilterDialogEventsSink
069:         * @see IFilterDialog
070:         */
071:        public class FilteredItemManager extends
072:                ProjectTreeFilterDialogEventsAdapter {
073:            private TreeMap m_FilterItems = new TreeMap();
074:            private TreeMap m_DiagramItems = new TreeMap();
075:            private IFilterItem m_AllModelItems = new FilterItem(
076:                    DefaultEngineResource.getString("IDS_MODEL_ELEMENTS"));
077:            private IFilterItem m_AllDiagramItems = new FilterItem(
078:                    DefaultEngineResource.getString("IDS_DIAGRAMS"));
079:
080:            /**
081:             * Initializes the filter items using a hash map.
082:             * 
083:             * @param displayedItems The display items.  The key is the element type and
084:             *                       the value is either "y" or "n".
085:             */
086:            public void initialize(HashMap displayedItems) {
087:                boolean addedImportPackages = false;
088:                boolean addedImportElements = false;
089:
090:                Set keySet = displayedItems.keySet();
091:                for (Iterator iter = keySet.iterator(); iter.hasNext();) {
092:                    String curKey = (String) iter.next();
093:                    if ((addedImportPackages == false)
094:                            && (curKey.equals("ImportedPackages") == true)) {
095:                        addedImportPackages = true;
096:                        m_FilterItems.put("ImportedPackages", new FilterItem(
097:                                "ImportedPackages",
098:                                IFilterItem.FILTER_STATE_OFF));
099:                    } else if ((addedImportPackages == false)
100:                            && (curKey.equals("ImportedElements") == true)) {
101:                        addedImportPackages = true;
102:                        m_FilterItems.put("ImportedElements", new FilterItem(
103:                                "ImportedElements",
104:                                IFilterItem.FILTER_STATE_OFF));
105:                    } else if (curKey.length() > 0) {
106:                        String value = (String) displayedItems.get(curKey);
107:
108:                        int fValue = (value.equalsIgnoreCase("y") == true ? IFilterItem.FILTER_STATE_ON
109:                                : IFilterItem.FILTER_STATE_OFF);
110:                        FilterItem item = new FilterItem(curKey, fValue);
111:                        m_FilterItems.put(curKey, item);
112:                    }
113:                }
114:
115:                m_DiagramItems.put("ActivityDiagram", new FilterItem(
116:                        "ActivityDiagram", IFilterItem.FILTER_STATE_ON));
117:                m_DiagramItems.put("ClassDiagram", new FilterItem(
118:                        "ClassDiagram", IFilterItem.FILTER_STATE_ON));
119:                m_DiagramItems.put("CollaborationDiagram", new FilterItem(
120:                        "CollaborationDiagram", IFilterItem.FILTER_STATE_ON));
121:                m_DiagramItems.put("ComponentDiagram", new FilterItem(
122:                        "ComponentDiagram", IFilterItem.FILTER_STATE_ON));
123:                m_DiagramItems.put("DeploymentDiagram", new FilterItem(
124:                        "DeploymentDiagram", IFilterItem.FILTER_STATE_ON));
125:                m_DiagramItems.put("SequenceDiagram", new FilterItem(
126:                        "SequenceDiagram", IFilterItem.FILTER_STATE_ON));
127:                m_DiagramItems.put("StateDiagram", new FilterItem(
128:                        "StateDiagram", IFilterItem.FILTER_STATE_ON));
129:                m_DiagramItems.put("UseCaseDiagram", new FilterItem(
130:                        "UseCaseDiagram", IFilterItem.FILTER_STATE_ON));
131:
132:                getFromRegistry();
133:            }
134:
135:            public void turnOffModelElements() {
136:                m_AllModelItems.setState(IFilterItem.FILTER_STATE_OFF);
137:            }
138:
139:            public void turnOnModelElements() {
140:                m_AllModelItems.setState(IFilterItem.FILTER_STATE_ON);
141:            }
142:
143:            public void turnOffDiagram() {
144:                m_AllDiagramItems.setState(IFilterItem.FILTER_STATE_OFF);
145:            }
146:
147:            public void turnOnDiagrams() {
148:                m_AllDiagramItems.setState(IFilterItem.FILTER_STATE_ON);
149:            }
150:
151:            /**
152:             * Checks if all model elements are to be filtered out.
153:             * 
154:             * @return <code>true</code> if all model elements are to be filtered out.
155:             *         <code>false</code> if not all model elements are to bed filtered
156:             *         out.
157:             */
158:            public boolean areAllModelElementsHidden() {
159:                return m_AllModelItems.getState() == IFilterItem.FILTER_STATE_OFF ? true
160:                        : false;
161:            }
162:
163:            /**
164:             * Checks if a item is to be displayed.
165:             * 
166:             * @param elementType The name of the item in the filter manager.
167:             * @return <code>true</code> if all model elements are to be filtered out.
168:             *         <code>false</code> if not all model elements are to bed filtered
169:             *         out.
170:             */
171:            public boolean isDisplayed(String elementType) {
172:                boolean retVal = false;
173:
174:                IFilterItem item = getFilterItem(elementType);
175:                if (item != null) {
176:                    retVal = (item.getState() == IFilterItem.FILTER_STATE_ON ? true
177:                            : false);
178:                }
179:
180:                return retVal;
181:            }
182:
183:            /**
184:             * Set the display state of the specified item.
185:             * 
186:             * @param elementType The name of the item in the filter manager.
187:             * @param show <code>true</code> if the item is to be displayed and 
188:             *             <code>false</code> if the item is not to be displayed.
189:             */
190:            public void setIsDisplayed(String elementType, boolean show) {
191:                IFilterItem item = getFilterItem(elementType);
192:                if (item != null) {
193:                    item.setState((show == true ? IFilterItem.FILTER_STATE_ON
194:                            : IFilterItem.FILTER_STATE_OFF));
195:                }
196:            }
197:
198:            /**
199:             * Check the filter items and hte diagram items to find the specified 
200:             * filter item.
201:             * 
202:             * @param elementType The name of the item to locate.
203:             * @return The filter item if found or <code>null</code> if the item is
204:             *         not found.
205:             */
206:            protected IFilterItem getFilterItem(String elementType) {
207:                IFilterItem retVal = (IFilterItem) m_FilterItems
208:                        .get(elementType);
209:                if (retVal == null) {
210:                    retVal = (IFilterItem) m_DiagramItems.get(elementType);
211:                }
212:
213:                return retVal;
214:            }
215:
216:            /* (non-Javadoc)
217:             * @see org.netbeans.modules.uml.ui.controls.filter.IProjectTreeFilterDialogEventsSink#OnProjectTreeFilterDialogInit(org.netbeans.modules.uml.ui.controls.filter.IFilterDialog, org.netbeans.modules.uml.core.support.umlsupport.IResultCell)
218:             */
219:            public void onProjectTreeFilterDialogInit(IFilterDialog dialog,
220:                    IResultCell cell) {
221:                // Restore the latest stuff from the registry
222:                getFromRegistry();
223:
224:                IFilterNode modelElementsNode = dialog
225:                        .createRootNode(m_AllModelItems);
226:                for (Iterator iter = m_FilterItems.values().iterator(); iter
227:                        .hasNext();) {
228:                    IFilterItem curItem = (IFilterItem) iter.next();
229:                    dialog.addFilterItem(modelElementsNode, curItem);
230:                }
231:
232:                IFilterNode diagramElementsNode = dialog
233:                        .createRootNode(m_AllDiagramItems);
234:                for (Iterator iter = m_DiagramItems.values().iterator(); iter
235:                        .hasNext();) {
236:                    IFilterItem curItem = (IFilterItem) iter.next();
237:                    dialog.addFilterItem(diagramElementsNode, curItem);
238:                }
239:            }
240:
241:            /**
242:             * Get the current settings from the registry.  In jUML, we are not using registry settings, so instead
243:             * we are using the UserSettings files.  These entries will be stored in the .Settings file so that they
244:             * are application wide.  The entries that will be written to the file will be those that are to be
245:             * excluded (or unchecked).
246:             */
247:            public void getFromRegistry() {
248:                UserSettings settings = new UserSettings();
249:                if (settings != null) {
250:                    // set the check of the top model elements/diagrams to off
251:                    // they will be set to on if any of its children are checked
252:                    m_AllModelItems.setState(IFilterItem.FILTER_STATE_OFF);
253:                    m_AllDiagramItems.setState(IFilterItem.FILTER_STATE_OFF);
254:                    for (Iterator iter = m_FilterItems.values().iterator(); iter
255:                            .hasNext();) {
256:                        IFilterItem curItem = (IFilterItem) iter.next();
257:                        if (curItem != null) {
258:                            String name = curItem.getName();
259:                            String value = settings
260:                                    .getFilterDialogModelElement(name);
261:                            if (value == null) {
262:                                // if there is no value in the file for this element type, it will be "on" or "checked"
263:                                curItem.setState(IFilterItem.FILTER_STATE_ON);
264:                                // if any one of the children are on, we will check the top "model elements"
265:                                m_AllModelItems
266:                                        .setState(IFilterItem.FILTER_STATE_ON);
267:                            } else {
268:                                // if there is an entry in the file for this element type, it will "unchecked"
269:                                curItem.setState(IFilterItem.FILTER_STATE_OFF);
270:                            }
271:                        }
272:                    }
273:                    for (Iterator iter = m_DiagramItems.values().iterator(); iter
274:                            .hasNext();) {
275:                        IFilterItem curItem = (IFilterItem) iter.next();
276:                        if (curItem != null) {
277:                            String name = curItem.getName();
278:                            String value = settings
279:                                    .getFilterDialogDiagram(name);
280:                            if (value == null) {
281:                                curItem.setState(IFilterItem.FILTER_STATE_ON);
282:                                // if any one of the children are on, we will check the top "node"
283:                                m_AllDiagramItems
284:                                        .setState(IFilterItem.FILTER_STATE_ON);
285:                            } else {
286:                                curItem.setState(IFilterItem.FILTER_STATE_OFF);
287:                            }
288:                        }
289:                    }
290:                }
291:            }
292:
293:            /**
294:             * Saves the current settings to the registry.  In jUML, we are not using registry settings, so instead
295:             * we are using the UserSettings files.  These entries will be stored in the .Settings file so that they
296:             * are application wide.  The entries that will be written to the file will be those that are to be
297:             * excluded (or unchecked).
298:             */
299:            public void saveToRegistry() {
300:                UserSettings settings = new UserSettings();
301:                if (settings != null) {
302:                    for (Iterator iter = m_FilterItems.values().iterator(); iter
303:                            .hasNext();) {
304:                        IFilterItem curItem = (IFilterItem) iter.next();
305:                        if (curItem != null) {
306:                            if (curItem.getState() == IFilterItem.FILTER_STATE_OFF) {
307:                                // if it is unchecked, then write it to the file
308:                                String name = curItem.getName();
309:                                settings.addFilterDialogModelElement(name);
310:                            } else {
311:                                // if it is checked, make sure it isn't in the file
312:                                String name = curItem.getName();
313:                                String value = settings
314:                                        .getFilterDialogModelElement(name);
315:                                if (value != null) {
316:                                    settings
317:                                            .removeFilterDialogModelElement(name);
318:                                }
319:                                // if one of the children are checked, need to make sure that the parent is checked
320:                                // because the user could have unchecked the parent, and then manually checked a child
321:                                // which would cause the parent to be out of synch
322:                                m_AllModelItems
323:                                        .setState(IFilterItem.FILTER_STATE_ON);
324:                            }
325:                        }
326:                    }
327:                    for (Iterator iter = m_DiagramItems.values().iterator(); iter
328:                            .hasNext();) {
329:                        IFilterItem curItem = (IFilterItem) iter.next();
330:                        if (curItem != null) {
331:                            if (curItem.getState() == IFilterItem.FILTER_STATE_OFF) {
332:                                // if it is unchecked, then write it to the file
333:                                String name = curItem.getName();
334:                                settings.addFilterDialogDiagram(name);
335:                            } else {
336:                                // if it is checked, make sure it isn't in the file
337:                                String name = curItem.getName();
338:                                String value = settings
339:                                        .getFilterDialogDiagram(name);
340:                                if (value != null) {
341:                                    settings.removeFilterDialogDiagram(name);
342:                                }
343:                                // if one of the children are checked, need to make sure that the parent is checked
344:                                // because the user could have unchecked the parent, and then manually checked a child
345:                                // which would cause the parent to be out of synch
346:                                m_AllDiagramItems
347:                                        .setState(IFilterItem.FILTER_STATE_ON);
348:                            }
349:                        }
350:                    }
351:                }
352:            }
353:
354:        }
ww_w___.ja___v_a2___s.c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.