Source Code Cross Referenced for CommandStateHelper.java in  » Database-Client » dbmjui » fr » aliacom » dbmjui » ui » 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 » Database Client » dbmjui » fr.aliacom.dbmjui.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Created on Mar 10, 2003
003:         *
004:         * Dbmjui is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License version 2 as
006:         * published by the Free Software Foundation.
007:         *  
008:         * Dbmjui 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:         * General Public License for more details.
012:         *  
013:         * You should have received a copy of the GNU General Public
014:         * License along with dbmjui; see the file COPYING.  If not,
015:         * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
016:         * Boston, MA 02111-1307, USA.
017:         *
018:         */
019:        package fr.aliacom.dbmjui.ui;
020:
021:        import java.io.BufferedReader;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.io.InputStreamReader;
025:        import java.util.ArrayList;
026:
027:        import org.apache.log4j.Logger;
028:
029:        import fr.aliacom.commands.CommandPool;
030:        import fr.aliacom.dbmjui.DbState;
031:        import fr.aliacom.form.common.FormContext;
032:        import fr.aliacom.form.common.ToolkitManager;
033:
034:        /**
035:         * This helper class will enable/disable the commands to
036:         * reflect the state of the selected instance.
037:         * 
038:         * @author tom
039:         *
040:         * (c) 2001, 2003 Thomas Cataldo
041:         */
042:        public final class CommandStateHelper {
043:
044:            /** List all the script names used by commands disabled in ADMIN mode */
045:            private static final ArrayList ADMIN_COMMANDS = new ArrayList();
046:
047:            /** List all the script names used by commands disabled in OFFLINE mode */
048:            private static final ArrayList OFFLINE_COMMANDS = new ArrayList();
049:
050:            /** List all the script names used by commands disabled in ONLINE mode */
051:            private static final ArrayList ONLINE_COMMANDS = new ArrayList();
052:
053:            private static final Logger log = Logger
054:                    .getLogger(CommandStateHelper.class);
055:
056:            static {
057:                try {
058:                    initialiseCommandStateLists();
059:                    log.debug("Command state list read correctly.");
060:                } catch (IOException e) {
061:                    e.printStackTrace();
062:                    log.debug("Cannot read disabled command list");
063:                    System.exit(1);
064:                }
065:            }
066:
067:            private static void initialiseCommandStateLists()
068:                    throws IOException {
069:                fillList(
070:                        ADMIN_COMMANDS,
071:                        ClassLoader
072:                                .getSystemResourceAsStream("ressources/adminCommands.txt"));
073:                fillList(
074:                        OFFLINE_COMMANDS,
075:                        ClassLoader
076:                                .getSystemResourceAsStream("ressources/offlineCommands.txt"));
077:                fillList(
078:                        ONLINE_COMMANDS,
079:                        ClassLoader
080:                                .getSystemResourceAsStream("ressources/onlineCommands.txt"));
081:            }
082:
083:            private static void fillList(ArrayList list, InputStream is)
084:                    throws IOException {
085:                BufferedReader reader = new BufferedReader(
086:                        new InputStreamReader(is));
087:                String line;
088:                while ((line = reader.readLine()) != null) {
089:                    line = line.trim();
090:                    if (!(line.length() == 0) && !line.startsWith("#")) {
091:                        list.add(line);
092:                    }
093:                }
094:                reader.close();
095:            }
096:
097:            /**
098:             * Change the UI state from oldState to newState.
099:             * All the disabled oldState commands will be re-enabled,
100:             * then all the newState commands will be disabled 
101:             * 
102:             * @param oldState one of the {@link DbState} constants
103:             * @param newState one of the {@link DbState} constants
104:             */
105:            public static void setCommandStates(int oldState, int newState) {
106:                setEnabled(getList(oldState), true);
107:                setEnabled(getList(newState), false);
108:            }
109:
110:            /**
111:             * Get the list of scripts disabled in a given database state.
112:             * 
113:             * @param state one of the {@link DbState} constants
114:             * @return the list of scripts disabled in the given mode
115:             */
116:            private static ArrayList getList(int state) {
117:                switch (state) {
118:                case DbState.COLD_STATE:
119:                    return ADMIN_COMMANDS;
120:                case DbState.WARM_STATE:
121:                    return ONLINE_COMMANDS;
122:                default:
123:                case DbState.STOP_STATE:
124:                    return OFFLINE_COMMANDS;
125:                }
126:            }
127:
128:            private static void setEnabled(ArrayList commandNames,
129:                    boolean enabled) {
130:                FormContext ctx = ToolkitManager.getToolkit().getMainWindow()
131:                        .getFormContext();
132:                for (int i = 0, n = commandNames.size(); i < n; i++) {
133:                    CommandPool.getInstance().setEnabled(ctx,
134:                            (String) commandNames.get(i), enabled);
135:                }
136:            }
137:
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.