Source Code Cross Referenced for SalomeTMF_Cmd.java in  » Test-Coverage » salome-tmf » org » objectweb » salome_tmf » ihm » main » 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 » Test Coverage » salome tmf » org.objectweb.salome_tmf.ihm.main 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.salome_tmf.ihm.main;
002:
003:        import java.awt.Frame;
004:        import java.awt.event.WindowEvent;
005:        import java.awt.event.WindowListener;
006:        import java.io.IOException;
007:        import java.net.URL;
008:        import java.util.Locale;
009:
010:        import org.objectweb.salome_tmf.api.Api;
011:        import org.objectweb.salome_tmf.api.MD5paswd;
012:        import org.objectweb.salome_tmf.ihm.languages.Language;
013:        import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
014:
015:        public class SalomeTMF_Cmd implements  BaseIHM, WindowListener {
016:
017:            private static String strProject = null;
018:            private static String strLogin = null;
019:            private static String urlSalome = null;
020:
021:            Frame ptrFrame;
022:
023:            /***************************************************************************************/
024:            SalomeTMFContext pSalomeTMFContext;
025:            SalomeTMFPanels pSalomeTMFPanels;
026:
027:            /****************************************************************************************/
028:
029:            public void quit(boolean do_recup, boolean doclose) {
030:                if (Api.isConnected() && doclose) {
031:                    Api.closeConnection();
032:                }
033:                System.exit(0);
034:            }
035:
036:            /********************************************************/
037:            boolean connectToAPI() {
038:                try {
039:                    Api.openConnection(new URL(urlSalome));
040:                    if (!Api.isConnected()) {
041:                        quit(false, false);
042:                    }
043:                    /* IF No cmd line */
044:                    if (strProject == null && strLogin == null) {
045:                        ProjectLogin dialog = new ProjectLogin(null);
046:                        dialog.setVisible(true);
047:                        if (dialog.getSelectedProject() != null
048:                                && dialog.getSelectedUser() != null) {
049:                            strProject = dialog.getSelectedProject();
050:                            strLogin = dialog.getSelectedUser();
051:                            //            		 Récupération du login et du mot de passe pour l'authentification
052:                            try {
053:                                Api.setStrUsername(strLogin);
054:                                Api.setStrMD5Password(MD5paswd
055:                                        .getEncodedPassword(dialog
056:                                                .getSelectedPassword()));
057:                            } catch (Exception e) {
058:                                e.printStackTrace();
059:                            }
060:                            Api.initConnectionUser(strProject, strLogin);
061:                        } else {
062:                            quit(true, true);
063:                            return false;
064:                        }
065:                    } else {
066:                        Api.initConnectionUser(strProject, strLogin);
067:                    }
068:
069:                    /* IF cmd line */
070:                    //Api.initConnectionUser(strProject, strLogin);
071:                } catch (Exception e) {
072:
073:                }
074:                return true;
075:            }
076:
077:            void onInit() {
078:                if (connectToAPI()) {
079:                    initComponent();
080:                    loadModel();
081:                    loadPlugin();
082:                }
083:
084:            }
085:
086:            void loadPlugin() {
087:                pSalomeTMFContext.loadPlugin(pSalomeTMFPanels);
088:            }
089:
090:            void loadModel() {
091:                DataModel.loadFromBase(strProject, strLogin, this );
092:                //IF No cmd Line *//
093:                pSalomeTMFPanels.loadModel(strProject, strLogin);
094:            }
095:
096:            void initComponent() {
097:                try {
098:                    URL pUrlSalome = new URL(urlSalome);
099:                    Api.setUrlBase(pUrlSalome);
100:                    Language.getInstance().setLocale(
101:                            new Locale(Api.getUsedLocale()));
102:                    ptrFrame = new Frame();
103:                    ptrFrame.addWindowListener(this );
104:                    ptrFrame.setVisible(true);
105:                    pSalomeTMFContext = new SalomeTMFContext(pUrlSalome,
106:                            ptrFrame, this );
107:                    pSalomeTMFPanels = new SalomeTMFPanels(pSalomeTMFContext,
108:                            this );
109:                    pSalomeTMFPanels.initComponentPanel();
110:
111:                    /* IF no cmd line */
112:                    ptrFrame.add(pSalomeTMFPanels.tabs);
113:                    ptrFrame.pack();
114:
115:                } catch (Exception e) {
116:                    e.printStackTrace();
117:                }
118:            }
119:
120:            public SalomeTMFContext getSalomeTMFContext() {
121:                return pSalomeTMFContext;
122:            }
123:
124:            public SalomeTMFPanels getSalomeTMFPanels() {
125:                return pSalomeTMFPanels;
126:            }
127:
128:            public void showDocument(URL toShow, String where) {
129:                switch (getPlatform()) {
130:                case (WIN_ID): {
131:                    System.out.println("Try Windows Command Line");
132:                    runCmdLine(replaceToken(WIN_CMDLINE, URLTOKEN, toShow
133:                            .toString()));
134:                }
135:                case (MAC_ID): {
136:                    System.out.println("Try Mac Command Line");
137:                    runCmdLine(replaceToken(MAC_CMDLINE, URLTOKEN, toShow
138:                            .toString()));
139:
140:                }
141:                default:
142:                    System.out.println("Try Unix Command Line");
143:                    for (int i = 0; i < OTHER_CMDLINES.length; i++) {
144:                        if (runCmdLine(replaceToken(OTHER_CMDLINES[i],
145:                                URLTOKEN, toShow.toString()),
146:                                replaceToken(OTHER_FALLBACKS[i], URLTOKEN,
147:                                        toShow.toString())))
148:                            return;
149:                    }
150:                }
151:            }
152:
153:            public boolean isGraphique() {
154:                // IF NO CMD Line	
155:                return true;
156:            }
157:
158:            /******************/
159:            /* This token is a placeholder for the actual URL */
160:            private final String URLTOKEN = "%URLTOKEN%";
161:
162:            // Used to identify the windows platform.
163:            private final int WIN_ID = 1;
164:
165:            // Used to discover the windows platform.
166:            private final String WIN_PREFIX = "Windows";
167:
168:            // The default system browser under windows.
169:            // Once upon a time:
170:            //   for 'Windows 9' and 'Windows M': start
171:            //   for 'Windows': cmd /c start
172:            private final String[] WIN_CMDLINE = { "rundll32",
173:                    "url.dll,FileProtocolHandler", URLTOKEN };
174:
175:            // Used to identify the mac platform.
176:            private final int MAC_ID = 2;
177:
178:            // Used to discover the mac platform.
179:            private final String MAC_PREFIX = "Mac";
180:
181:            // The default system browser under mac.
182:            private final String[] MAC_CMDLINE = { "open", URLTOKEN };
183:
184:            // Used to identify the mac platform.
185:            private final int OTHER_ID = -1;
186:
187:            private final String[][] OTHER_CMDLINES = {
188:
189:            // The first guess for a browser under other systems (and unix):
190:                    // Remote controlling firefox
191:                    // (http://www.mozilla.org/unix/remote.html)
192:                    { "firefox", "-remote",
193:                            "openURL(" + URLTOKEN + ",new-window)" },
194:
195:                    //	Remote controlling mozilla
196:                    // (http://www.mozilla.org/unix/remote.html)
197:                    { "mozilla", "-remote",
198:                            "openURL(" + URLTOKEN + ",new-window)" },
199:                    // The second guess for a browser under other systems (and unix):
200:                    // The RedHat skript htmlview
201:                    { "htmlview", URLTOKEN },
202:
203:                    // The third guess for a browser under other systems (and unix):
204:                    // Remote controlling netscape
205:                    // (http://wp.netscape.com/newsref/std/x-remote.html)
206:                    { "netscape", "-remote", "openURL(" + URLTOKEN + ")" }
207:
208:            };
209:
210:            private final String[][] OTHER_FALLBACKS = {
211:
212:            // Fallback for remote controlling mozilla:
213:                    //Starting up a new mozilla
214:                    { "firefox", URLTOKEN },
215:
216:                    // Starting up a new mozilla
217:                    { "mozilla", URLTOKEN },
218:
219:                    // No fallback for htmlview
220:                    null,
221:
222:                    // Fallback for remote controlling netscape:
223:                    // Starting up a new netscape
224:                    { "netscape", URLTOKEN }
225:
226:            };
227:
228:            private int getPlatform() {
229:                String os = System.getProperty("os.name");
230:                if (os != null && os.startsWith(WIN_PREFIX))
231:                    return WIN_ID;
232:                if (os != null && os.startsWith(MAC_PREFIX))
233:                    return MAC_ID;
234:                return OTHER_ID;
235:            }
236:
237:            private String[] replaceToken(String[] target, String token,
238:                    String replacement) {
239:                if (null == target)
240:                    return null;
241:                String[] result = new String[target.length];
242:
243:                for (int i = 0; i < target.length; i++)
244:                    result[i] = target[i].replaceAll(token, replacement);
245:
246:                return result;
247:            }
248:
249:            private boolean runCmdLine(String[] cmdLine) {
250:                System.out.println("Try to execute commande line    = "
251:                        + cmdLine);
252:                return runCmdLine(cmdLine, null);
253:            }
254:
255:            private boolean runCmdLine(String[] cmdLine,
256:                    String[] fallBackCmdLine) {
257:                try {
258:                    System.out.println("Try to execute commande line    = "
259:                            + cmdLine + " with " + fallBackCmdLine);
260:                    /*
261:                     * System.out.println( "Trying to invoke browser, cmd='" +
262:                     * connectStringArray(cmdLine) + "' ... ");
263:                     */
264:                    Process p = Runtime.getRuntime().exec(cmdLine);
265:
266:                    if (null != fallBackCmdLine) {
267:                        // wait for exit code -- if it's 0, command worked,
268:                        // otherwise we need to start fallBackCmdLine.
269:                        int exitCode = p.waitFor();
270:                        if (exitCode != 0) {
271:                            /*
272:                             * System.out.println(exitCode); System.out.println();
273:                             */
274:
275:                            /*
276:                             * System.out.println( "Trying to invoke browser, cmd='" +
277:                             * connectStringArray(fallBackCmdLine) + "' ...");
278:                             */
279:                            Runtime.getRuntime().exec(fallBackCmdLine);
280:
281:                        }
282:                    }
283:
284:                    System.out.println();
285:                    return true;
286:
287:                } catch (InterruptedException e) {
288:                    System.out.println("Caught: " + e);
289:                } catch (IOException e) {
290:                    System.out.println("Caught: " + e);
291:                }
292:
293:                return false;
294:            }
295:
296:            /******************/
297:
298:            /***************** Windows Listener ***************/
299:            public void windowClosing(WindowEvent e) {
300:                quit(true, true);
301:            }
302:
303:            public void windowActivated(WindowEvent e) {
304:            }
305:
306:            public void windowClosed(WindowEvent e) {
307:            }
308:
309:            public void windowDeactivated(WindowEvent e) {
310:            }
311:
312:            public void windowDeiconified(WindowEvent e) {
313:            }
314:
315:            public void windowIconified(WindowEvent e) {
316:            }
317:
318:            public void windowOpened(WindowEvent e) {
319:            }
320:
321:            public static void main(String[] args) {
322:                SalomeTMF_Cmd pSalomeTMF_Cmd = new SalomeTMF_Cmd();
323:                /* IF cmd line sample */
324:                //strLogin = "marchemi";
325:                //strProject = "salome-demo";
326:                urlSalome = "http://salome-tmf.rd.francetelecom.fr/www/salome-demo/salome_tmf/";
327:                pSalomeTMF_Cmd.onInit();
328:
329:                /* IF cmd line sample */
330:                /*try {
331:                Campaign pCamp = DataModel.getCurrentProject().getCampaignFromModel("Cauto");
332:                Execution pExec = pCamp.getExecutionFromModel("Exec0");
333:                ArrayList arrayExec = new ArrayList();
334:                arrayExec.add(pExec);
335:                TestMethods.runExecution(arrayExec, ((Component) new Frame()), false);
336:                } catch(Exception  e){
337:                	e.printStackTrace();
338:                }*/
339:            }
340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.