001: package com.xoetrope.editor.netbeans.visualizer;
002:
003: import com.xoetrope.carousel.visualizer.VisualiserContainer;
004: import com.xoetrope.carousel.visualizer.VisualiserProxy;
005: import com.xoetrope.data.pojo.XPojoModelEx;
006: import java.util.Observable;
007: import java.util.Observer;
008: import java.util.Vector;
009: import javax.swing.JOptionPane;
010: import org.openide.windows.Mode;
011: import org.openide.windows.TopComponent;
012: import org.openide.windows.WindowManager;
013:
014: import java.awt.BorderLayout;
015: import java.awt.CardLayout;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018: import javax.swing.ButtonGroup;
019: import javax.swing.JPanel;
020: import javax.swing.JToggleButton;
021: import javax.swing.JToolBar;
022: import net.xoetrope.editor.netbeans.project.pages.PagePanel;
023: import net.xoetrope.editor.project.XEditorProject;
024: import net.xoetrope.editor.project.pages.events.ComponentSelectListener;
025: import net.xoetrope.editor.project.pages.IXPagePanel;
026: import net.xoetrope.editor.project.pages.XComponentSizer;
027: import net.xoetrope.editor.project.pages.components.ComponentHelper;
028: import net.xoetrope.editor.project.pages.components.PropertyHelper;
029: import net.xoetrope.editor.project.pages.PageDesigner;
030: import net.xoetrope.editor.project.pages.XPagePanel;
031: import net.xoetrope.editor.project.workspace.ComponentToolBar;
032: import net.xoetrope.xui.XProject;
033: import net.xoetrope.xui.XProjectManager;
034:
035: /**
036: * A topComponent to support visualization of the data model
037: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
038: * the GNU Public License (GPL), please see license.txt for more details. If
039: * you make commercial use of this software you must purchase a commercial
040: * license from Xoetrope.</p>
041: * <p> $Revision: 1.21 $</p>
042: */
043: public class VisualiserPalette extends TopComponent implements
044: VisualiserProxy, ComponentSelectListener, ActionListener {
045: private VisualiserContainer designVisualizerContainer,
046: debugVisualiserContainer;
047: private XProject currentProject;
048: private Vector activeComponents;
049: private IXPagePanel activePage;
050: private JToggleButton designTimeButton, runTimeButton;
051: private JPanel contentPanel;
052: private CardLayout panelManager;
053:
054: public VisualiserPalette() {
055: currentProject = XProjectManager.getCurrentProject();
056: setName("Visualizer ("
057: + currentProject.getStartupParam("ProjectPath") + ")");
058:
059: JToolBar toolbar = new ComponentToolBar();
060:
061: // selection button
062: ButtonGroup bg = new ButtonGroup();
063: designTimeButton = new JToggleButton("Design time");
064: designTimeButton.setActionCommand("Design");
065: designTimeButton.addActionListener(this );
066: designTimeButton
067: .setToolTipText("Design time view of the data model");
068: designTimeButton.setSelected(true);
069: bg.add(designTimeButton);
070:
071: runTimeButton = new JToggleButton("Run time");
072: runTimeButton.setActionCommand("Runtime");
073: runTimeButton.addActionListener(this );
074: runTimeButton
075: .setToolTipText("Run-time/Debug view of the data model");
076: runTimeButton.setSelected(false);
077: bg.add(runTimeButton);
078:
079: toolbar.add(designTimeButton);
080: toolbar.add(runTimeButton);
081:
082: Vector customCompSelectListeners = (Vector) currentProject
083: .getObject("CustomCompSelectListeners");
084: if (customCompSelectListeners == null)
085: customCompSelectListeners = new Vector();
086:
087: customCompSelectListeners.add(this );
088: currentProject.setObject("CustomCompSelectListeners",
089: customCompSelectListeners);
090:
091: debugVisualiserContainer = new VisualiserContainer(
092: new NbDebuggerEngine());
093: debugVisualiserContainer.setVisible(true);
094:
095: designVisualizerContainer = new VisualiserContainer(null);
096: designVisualizerContainer.setVisible(true);
097:
098: contentPanel = new JPanel();
099: panelManager = new CardLayout();
100: contentPanel.setLayout(panelManager);
101:
102: contentPanel.add(designVisualizerContainer, "Design time");
103: contentPanel.add(debugVisualiserContainer, "Run time");
104:
105: setLayout(new BorderLayout());
106: add(toolbar, BorderLayout.NORTH);
107: add(contentPanel, BorderLayout.CENTER);
108: //visualiserPanel.setModelTreeListener( this );
109:
110: setComponentListeners();
111: }
112:
113: public void componentActivated() {
114: debugVisualiserContainer.refresh();
115: }
116:
117: public void actionPerformed(ActionEvent e) {
118: Object o = e.getSource();
119: String page = (o == designTimeButton ? "Design time"
120: : "Run time");
121: if (page != null)
122: panelManager.show(contentPanel, page);
123: }
124:
125: private void setComponentListeners() {
126: if (debugVisualiserContainer != null)
127: debugVisualiserContainer.setVisualiserProxy(this );
128: designVisualizerContainer.setVisualiserProxy(this );
129: Mode m = WindowManager.getDefault().findMode("editor");
130: TopComponent[] components = m.getTopComponents();
131: for (int i = 0; i < components.length; i++) {
132: if (components[i] instanceof PagePanel) {
133: PageDesigner pd = ((PagePanel) components[i])
134: .getPageDesigner();
135: pd.addComponentSelectionListener(this );
136: }
137: }
138: }
139:
140: public void nodeDoubleClicked(String path) {
141: if ((activeComponents != null) && (activeComponents.size() > 0)) {
142: XComponentSizer comp = (XComponentSizer) activeComponents
143: .get(0);
144: if (comp.isValid()) {
145: PropertyHelper helper = new ComponentHelper()
146: .getPropertyHelper(comp.getTarget());
147: helper.setPropertyValue(comp.getPageResource(), comp,
148: "Data", path);
149: XEditorProject proj = (XEditorProject) currentProject;
150: ((XPagePanel) activePage).componentChanged();
151: activePage.setModified(true);
152: }
153: }
154: }
155:
156: public void open() {
157: Mode mode = WindowManager.getDefault().findMode("output");
158: if (mode != null)
159: mode.dockInto(this );
160: super .open();
161: }
162:
163: /*public void componentClosed()
164: {
165: currentProject.removeComponentSelectionListener( this );
166: }*/
167:
168: public void setSelectedComponents(IXPagePanel currentPanel,
169: Vector selectedComponents, boolean contentsChanged) {
170: if (!contentsChanged)
171: return;
172: activeComponents = selectedComponents;
173: activePage = currentPanel;
174: if (selectedComponents.size() > 0) {
175: XComponentSizer comp = (XComponentSizer) selectedComponents
176: .get(0);
177: PropertyHelper helper = new ComponentHelper()
178: .getPropertyHelper(comp.getTarget());
179: String attributeValue = helper.getPropertyValue(comp
180: .getPageResource(), comp.getTarget(), "Data");
181: if (debugVisualiserContainer != null)
182: debugVisualiserContainer
183: .setSelectedPath(attributeValue);
184: designVisualizerContainer.setSelectedPath(attributeValue);
185: }
186: }
187:
188: public String preferredID() {
189: return "XuiProDataVisualizer";
190: }
191:
192: /**
193: * @todo When the class has stabilized remove this method and retest the persistence
194: * @return
195: */
196: public int getPersistenceType() {
197: return PERSISTENCE_NEVER;
198: }
199:
200: /*public void loadDatasets()
201: {
202: XDataSource modelDataSource = new XDataSource();
203: try {
204: String fileName = currentProject.getStartupParam( "ModelData" );
205: if ( fileName != null ) {
206: try {
207: modelDataSource.read( currentProject.getBufferedReader( fileName, null ) );
208: }
209: catch ( Exception ex3 ) {
210: if ( BuildProperties.DEBUG )
211: DebugLogger.logError( "Could not access file:" + fileName );
212: }
213: }
214: }
215: catch ( Exception ex ) {
216: if ( BuildProperties.DEBUG )
217: DebugLogger.logError( "Exception in loadDatasets" );
218: }
219: }*/
220: }
|