View Javadoc

1   package net.sf.mmapps.applications.developer.project;
2   
3   import java.awt.BorderLayout;
4   import java.io.File;
5   import java.util.*;
6   import javax.swing.*;
7   import javax.swing.tree.DefaultTreeModel;
8   
9   import net.sf.mmapps.applications.developer.Developer;
10  import net.sf.mmapps.applications.developer.dialog.ExceptionDialog;
11  import net.sf.mmapps.modules.config.*;
12  public class ProjectPanel extends JPanel {
13  
14      //JSplitPane splitPane ;
15      Configuration config;
16      ProjectTree projectTree;
17      public ProjectPanel() {
18          super();
19  
20          config = new Configuration();
21          setLayout(new BorderLayout());
22          
23          //splitPane = new JSplitPane();
24          //splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
25          
26          projectTree = new ProjectTree(new ProjectRootMutableTreeNode());
27          JScrollPane scrollPane = new JScrollPane();
28          scrollPane.setViewportView(projectTree);
29          add(scrollPane, BorderLayout.CENTER);
30  
31          //splitPane.setTopComponent(projectTree);
32          //splitPane.setBottomComponent(new JButton("MMBase"));
33          
34          //add(splitPane,BorderLayout.CENTER);
35  		//splitPane.setDividerLocation(.9);
36      }
37  
38      public void clearProject() {
39          config = new Configuration();
40          updateTree();
41      }
42      
43      public void addApplicationConfiguration(ApplicationConfiguration appConfig) {
44          config.addApplicationConfiguration(appConfig);
45          updateTree();
46      }
47  
48      public void importConfiguration(File dir) {
49          try {
50              MMBaseFileConfigurationReader mmbaseFileConfigurationReader = new MMBaseFileConfigurationReader();
51              mmbaseFileConfigurationReader.readConfiguration(config, dir);
52          } catch (Exception ioe) {
53              new ExceptionDialog(Developer.getInstance(), "error while importing the configuration", ioe).show();
54          }
55          updateTree();
56      }
57  
58      public void updateTree() {
59          ProjectRootMutableTreeNode rootNode = (ProjectRootMutableTreeNode) projectTree.getModel().getRoot();
60          rootNode.removeAllChildren();
61          NodeManagerConfigurations nodeManagerConfigurations = config.getNodeManagerConfigurations();
62          Collections.sort(nodeManagerConfigurations, new NodeManagerConifguartionComparator());
63          if (nodeManagerConfigurations.size() > 0) {
64              ProjectDirectoryMutableTreeNode projectDirectoryMutableTreeNode = new ProjectDirectoryMutableTreeNode("core builders");
65              for (int x = 0; x < nodeManagerConfigurations.size(); x++) {
66                  NodeManagerConfiguration nodeManagerConfiguration = nodeManagerConfigurations.getNodeManagerConfiguration(x);
67                  projectDirectoryMutableTreeNode.add(new NodeManagerConfigurationMutableTreeNode(config, "Core", nodeManagerConfiguration));
68              }
69              rootNode.add(projectDirectoryMutableTreeNode);
70          }
71  
72          ApplicationConfigurations applicationConfigurations = config.getApplicationConfigurations();
73          if (applicationConfigurations.size() > 0) {
74              ProjectDirectoryMutableTreeNode projectDirectoryMutableTreeNode = new ProjectDirectoryMutableTreeNode("applications");
75              for (int x = 0; x < applicationConfigurations.size(); x++) {
76                  ApplicationConfiguration applicationConfiguration = applicationConfigurations.getApplicationConfiguration(x);
77                  projectDirectoryMutableTreeNode.add(new ApplicationConfigurationMutableTreeNode(config, applicationConfiguration));
78              }
79              rootNode.add(projectDirectoryMutableTreeNode);
80          }
81  
82          if (projectTree.getModel() instanceof DefaultTreeModel) {
83              DefaultTreeModel mod = (DefaultTreeModel) projectTree.getModel();
84              mod.nodeStructureChanged(rootNode);
85  
86          }
87      }
88      
89      public Configuration getConfiguration(){
90      	return config;
91      }
92      
93  	class NodeManagerConifguartionComparator implements Comparator {
94  		public int compare(Object o1, Object o2) {
95  			NodeManagerConfiguration a = (NodeManagerConfiguration) o1;
96  			NodeManagerConfiguration b = (NodeManagerConfiguration) o2;
97  			return a.getName().compareTo(b.getName());
98  		}
99  
100 	}
101 }