1 package net.sf.mmapps.applications.developer;
2
3 import java.util.HashMap;
4
5 import net.sf.mmapps.applications.developer.dialog.*;
6 import org.mmbase.bridge.*;
7 import net.sf.mmapps.modules.config.*;
8 import net.sf.mmapps.modules.config.dumper.Dumper;
9
10 public class MMBaseLiveConfigurationReader implements Runnable {
11 private StatusBar statusBar;
12 /*** Creates a new instance of MMBaseLiveConfigurationReader */
13 public MMBaseLiveConfigurationReader() {
14
15 }
16
17 public void startRead() {
18 new Thread(this).start();
19 }
20
21 public void setStatus(String status) {
22 if (statusBar == null) {
23 System.out.println(status);
24 return;
25 }
26 statusBar.showStatus(status);
27
28
29 int statusBarValue = statusBar.getValue();
30 if (statusBarValue < 98) {
31 statusBar.setValue(++statusBarValue);
32 }
33 }
34
35 public void run() {
36 Developer developer = Developer.getInstance();
37 statusBar = developer.getStatusBar();
38 try {
39 setStatus("getting context information");
40 statusBar.setValue(0);
41 AddContextDialog addContextDialog = new AddContextDialog(developer, true);
42 addContextDialog.show();
43 if (addContextDialog.getAction() == DefaultDialog.ACTION_OK) {
44 setStatus("getting account information");
45 statusBar.setValue(10);
46 String contextName = addContextDialog.getContextName();
47 String contextUrl = addContextDialog.getContextURL();
48 CloudContext cloudContext = ContextProvider.getCloudContext(contextUrl);
49 UserPasswordDialog userPasswordDialog = new UserPasswordDialog(developer, contextName, true);
50 userPasswordDialog.show();
51 Cloud cloud = null;
52 if (userPasswordDialog.getAction() == UserPasswordDialog.ACTION_OK) {
53 statusBar.setValue(20);
54 setStatus("getting a cloud for account " + userPasswordDialog.getUserName());
55 HashMap user = new HashMap();
56 user.put("username", userPasswordDialog.getUserName());
57 user.put("password", userPasswordDialog.getPassword());
58 cloud = cloudContext.getCloud("mmbase", "name/password", user);
59
60 } else {
61 setStatus("getting anon cloud");
62 statusBar.setValue(20);
63 cloud = cloudContext.getCloud("mmbase");
64 }
65 setStatus("reading cloud information");
66 Configuration config =Dumper.getConfiguration(cloud);
67 setStatus("adding cloud application to project panel");
68 statusBar.setValue(100);
69 if (config.getApplicationConfigurations().size() == 1){
70 developer.getExplorerPanel().getProjectPanel().addApplicationConfiguration(config.getApplicationConfigurations().getApplicationConfiguration(0));
71 }
72 setStatus("finised");
73 } else {
74 setStatus("canceled import live cloud");
75
76 }
77 } catch (Throwable t) {
78 new ExceptionDialog(developer, "error while reading the live cloud information", t).show();
79 }
80 }
81 }