001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.Container;
004: import java.awt.Frame;
005: import java.awt.event.WindowAdapter;
006: import java.awt.event.WindowEvent;
007: import java.net.URL;
008: import java.util.Locale;
009:
010: import javax.jnlp.BasicService;
011: import javax.jnlp.ServiceManager;
012: import javax.jnlp.UnavailableServiceException;
013: import javax.swing.JFrame;
014: import javax.swing.LookAndFeel;
015: import javax.swing.UIManager;
016:
017: import org.objectweb.salome_tmf.api.Api;
018: import org.objectweb.salome_tmf.api.MD5paswd;
019: import org.objectweb.salome_tmf.api.Util;
020: import org.objectweb.salome_tmf.ihm.languages.Language;
021: import org.objectweb.salome_tmf.ihm.main.datawrapper.DataModel;
022:
023: public class SalomeTMF_JWS implements BaseIHM {
024: protected URL urlSalome;
025: protected JFrame ptrFrame;
026:
027: protected String strProject = null;
028: protected String strLogin = null;
029:
030: /***************************************************************************************/
031: protected SalomeTMFContext pSalomeTMFContext;
032: protected SalomeTMFPanels pSalomeTMFPanels;
033:
034: /****************************************************************************************/
035:
036: protected SalomeTMF_JWS() {
037: if (connectToAPI()) {
038: WaitView waitView = new WaitView();
039: long l1 = System.currentTimeMillis();
040: initComponent();
041: loadModel();
042: loadPlugin();
043: long l2 = System.currentTimeMillis();
044: System.out.println("Temps de chargement = " + (l2 - l1));
045: waitView.dispose();
046: ptrFrame.pack();
047: ptrFrame.setVisible(true);
048: ptrFrame.addWindowListener(new WindowAdapter() {
049: public void windowClosing(WindowEvent e) {
050: quit(false, true);
051: }
052: });
053:
054: } else {
055: System.exit(0);
056: }
057:
058: }
059:
060: void initComponent() {
061: ptrFrame = new JFrame("SalomeTMF");
062:
063: Api.setUrlBase(urlSalome);
064: //System.out.println("URLBASE IS " + urlSalome);
065: try {
066: Class lnfClass = Class.forName(UIManager
067: .getSystemLookAndFeelClassName());
068: LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance());
069: UIManager.setLookAndFeel(newLAF);
070: Util.adaptFont();
071: } catch (Exception exc) {
072: System.err.println("Error loading L&F: " + exc);
073: }
074: Util.log("[SalomeTMF->initComponent] Used Local is "
075: + Api.getUsedLocale());
076: Language.getInstance().setLocale(
077: new Locale(Api.getUsedLocale()));
078:
079: pSalomeTMFContext = new SalomeTMFContext(urlSalome,
080: new Frame(), this );
081: pSalomeTMFPanels = new SalomeTMFPanels(pSalomeTMFContext, this );
082: pSalomeTMFPanels.initComponentPanel();
083:
084: Container cp = ptrFrame.getContentPane();
085: cp.add(pSalomeTMFPanels.tabs);
086:
087: }
088:
089: void loadPlugin() {
090: pSalomeTMFContext.loadPlugin(pSalomeTMFPanels);
091: pSalomeTMFContext.startPlugin();
092: }
093:
094: void loadModel() {
095: if (strProject == null || strLogin == null) {
096: quit(true, true);
097: }
098: DataModel.loadFromBase(strProject, strLogin, this );
099: pSalomeTMFPanels.loadModel(strProject, strLogin);
100: }
101:
102: /**************************************************************************************/
103: protected boolean connectToAPI() {
104: try {
105: // Lookup the javax.jnlp.BasicService object
106: BasicService bs = (BasicService) ServiceManager
107: .lookup("javax.jnlp.BasicService");
108: // Invoke the showDocument method
109: urlSalome = bs.getCodeBase();
110: Api.openConnection(urlSalome);
111:
112: ProjectLogin dialog = new ProjectLogin(null);
113: dialog.setVisible(true);
114: if (dialog.getSelectedProject() != null
115: && dialog.getSelectedUser() != null) {
116: strProject = dialog.getSelectedProject();
117: strLogin = dialog.getSelectedUser();
118: // Récupération du login et du mot de passe pour l'authentification
119: try {
120: Api.setStrUsername(strLogin);
121: Api.setStrMD5Password(MD5paswd
122: .getEncodedPassword(dialog
123: .getSelectedPassword()));
124: } catch (Exception e) {
125: e.printStackTrace();
126: }
127: Api.initConnectionUser(strProject, strLogin);
128: } else {
129: return false;
130: }
131: } catch (UnavailableServiceException ue) {
132: // Service is not supported
133: return false;
134: }
135: // strProject = "projet_test";
136: //strLogin = "marchemi";
137:
138: return true;
139: }
140:
141: /**********************************************************************************************************************/
142:
143: public void quit(boolean do_recup, boolean doclose) {
144: Util
145: .log("[SalomeTMF] - Applet quit (recup = " + do_recup
146: + ")");
147: if (pSalomeTMFContext != null && doclose == true) {
148: pSalomeTMFContext.suspendPlugin();
149: }
150: if (Api.isConnected() && doclose) {
151: Api.closeConnection();
152: }
153: System.exit(0);
154: } // Fin de la m?thode quit();
155:
156: public SalomeTMFContext getSalomeTMFContext() {
157: return pSalomeTMFContext;
158: }
159:
160: public SalomeTMFPanels getSalomeTMFPanels() {
161: return pSalomeTMFPanels;
162: }
163:
164: public void showDocument(URL toShow, String where) {
165: //getAppletContext().showDocument(toShow, where);
166: try {
167: // Lookup the javax.jnlp.BasicService object
168: BasicService bs = (BasicService) ServiceManager
169: .lookup("javax.jnlp.BasicService");
170: // Invoke the showDocument method
171: bs.showDocument(toShow);
172:
173: } catch (UnavailableServiceException ue) {
174: // Service is not supported
175:
176: }
177: }
178:
179: public boolean isGraphique() {
180: return true;
181: }
182:
183: public static void main(String arg[]) {
184: new SalomeTMF_JWS();
185: }
186: }
|