001: package com.xoetrope.editor.netbeans.services;
002:
003: //import com.baltimore.jcrypto.provider.crypto.cipher.Mode;
004:
005: import com.xoetrope.carousel.services.*;
006: import java.util.Enumeration;
007: import java.util.Hashtable;
008:
009: import java.awt.BorderLayout;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.Dimension;
013: import javax.swing.BorderFactory;
014: import javax.swing.JPanel;
015: import javax.swing.JScrollPane;
016: import javax.swing.JSplitPane;
017: import javax.swing.JTree;
018: import javax.swing.border.EmptyBorder;
019: import javax.swing.tree.DefaultMutableTreeNode;
020: import javax.swing.tree.TreePath;
021:
022: import net.xoetrope.editor.project.XEditorProject;
023: import net.xoetrope.xml.XmlElement;
024: import net.xoetrope.xui.data.XModel;
025: import net.xoetrope.xui.data.XBaseModel;
026:
027: import org.openide.windows.TopComponent;
028: import org.openide.text.CloneableEditorSupport;
029: import org.openide.windows.Mode;
030: import org.openide.windows.TopComponent;
031: import org.openide.windows.WindowManager;
032: import net.xoetrope.xui.helper.Constants;
033:
034: /**
035: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
036: * the GNU Public License (GPL), please see license.txt for more details. If
037: * you make commercial use of this software you must purchase a commercial
038: * license from Xoetrope.</p>
039: * <p> $Revision: 1.6 $</p>
040: */
041: public class ServiceEditor extends TopComponent implements
042: IServiceEditor {
043: private XEditorProject currentProject;
044: private Container toolbar;
045: private JTree servicesTree;
046: private JPanel editPanel;
047: private JSplitPane splitPane;
048: private JScrollPane servicesPane;
049: private DefaultMutableTreeNode topNode, clientNode, serverNode;
050: private ServiceDataEditor serviceDataEditor;
051:
052: public ServiceEditor(XEditorProject proj) {
053: currentProject = proj;
054: //setName( "Services (" + currentProject.getProjectTitle() + ")" );
055:
056: add(createToolbar(), BorderLayout.NORTH);
057:
058: servicesPane = new JScrollPane(servicesTree);
059: servicesPane.setBorder(BorderFactory.createEmptyBorder());
060: servicesPane.setViewportBorder(BorderFactory
061: .createEmptyBorder());
062: int preferredWidth = 200;
063: Mode explorerMode = WindowManager.getDefault().findMode(
064: "explorer");
065: //if ( explorerMode != null )
066: // preferredWidth = explorerMode.getSelectedTopComponent().getWidth();
067: servicesPane
068: .setPreferredSize(new Dimension(preferredWidth, 200));
069: serviceDataEditor = new ServiceDataEditor(this , proj);
070: getServiceManager().loadServicesFromFile(currentProject);
071: createTree();
072: editPanel = new JPanel(new BorderLayout());
073: editPanel.setBorder(BorderFactory.createEmptyBorder());
074: editPanel.add(serviceDataEditor);
075: splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
076: servicesPane, editPanel);
077: splitPane.setDividerSize(6);
078: splitPane.setDividerLocation(0.3);
079: splitPane.setBorder(BorderFactory.createEmptyBorder());
080: add(splitPane, BorderLayout.CENTER);
081: }
082:
083: private ServiceManager getServiceManager() {
084: return (ServiceManager) currentProject
085: .getObject(ProjectRouteManager.SERVICE_MGR_LOOKUP);
086: }
087:
088: /**
089: * Dock this TopComponent
090: */
091: /*public void open()
092: {
093: Mode mode = WindowManager.getDefault().findMode( "output" );
094: if ( mode != null )
095: mode.dockInto( this );
096: super.open();
097: }*/
098:
099: private Component createToolbar() {
100: setLayout(new BorderLayout());
101: toolbar = new JPanel(new BorderLayout());
102: return toolbar;
103: }
104:
105: public void createTree() {
106: topNode = new DefaultMutableTreeNode(Constants.SERVICES);
107: servicesTree = new JTree(topNode);
108: servicesTree.setEditable(true);
109: servicesTree.setBorder(BorderFactory.createEmptyBorder());
110:
111: servicesPane.setViewportView(servicesTree);
112: serviceDataEditor.setServiceTree(servicesTree);
113:
114: buildTree(topNode, null);
115: expandRoot();
116: }
117:
118: private void buildTree(DefaultMutableTreeNode parent, XmlElement ele) {
119: clientNode = new DefaultMutableTreeNode(Constants.CLIENT);
120: serverNode = new DefaultMutableTreeNode(Constants.SERVER);
121: parent.add(clientNode);
122: parent.add(serverNode);
123:
124: XBaseModel serviceMdl = getServiceManager().getServices(
125: ServiceManager.SIDE_CLIENT);
126: buildServiceTree(clientNode, serviceMdl);
127:
128: serviceMdl = getServiceManager().getServices(
129: ServiceManager.SIDE_SERVER);
130: buildServiceTree(serverNode, serviceMdl);
131: }
132:
133: private void buildServiceTree(DefaultMutableTreeNode parentNode,
134: XBaseModel serviceMdl) {
135: for (int i = 0; i < serviceMdl.getNumChildren(); i++) {
136: XBaseModel child = (XBaseModel) serviceMdl.get(i);
137: DefaultMutableTreeNode nodService = new DefaultMutableTreeNode(
138: child.getId());
139: parentNode.add(nodService);
140: }
141: }
142:
143: public void save() {
144: String filename = getModelManager().getServicesFileName();
145: if (filename != null)
146: getServiceManager().saveServices(currentProject);
147: }
148:
149: private ModelManager getModelManager() {
150: RouteManager routeMgr = (RouteManager) currentProject
151: .getObject(ProjectRouteManager.ROUTE_MGR_LOOKUP);
152: return routeMgr.getModelMgr();
153: }
154:
155: private void expandRoot() {
156: TreePath path = new TreePath(topNode);
157: servicesTree.expandPath(path);
158: servicesTree.repaint();
159: }
160:
161: /*public String preferredId()
162: {
163: return "XuiProServiceEditor";
164: }*/
165:
166: /**
167: * @todo When the class has stabilized remove this method and retest the persistence
168: * @return
169: */
170: /*public int getPersistenceType()
171: {
172: return PERSISTENCE_NEVER;
173: }*/
174: }
|